Skip to content

Commit b0b2ea8

Browse files
author
Joerg Huber
committed
Restructuring due to maven build.
1 parent 2c2023f commit b0b2ea8

7 files changed

Lines changed: 1016 additions & 0 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/event/
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/DailyAttendanceEvents.java
Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
1+
/*
2+
* TestEventClient.java
3+
* Created: 21/03/2014
4+
*
5+
* Copyright 2014 Systemic Pty Ltd
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software distributed under the License
14+
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
15+
* or implied.
16+
* See the License for the specific language governing permissions and limitations under the License.
17+
*/
18+
19+
package sif3.test.infra.rest.client;
20+
21+
import java.net.URI;
22+
23+
import javax.ws.rs.core.MediaType;
24+
25+
import sif.dd.au30.conversion.DataModelMarshalFactory;
26+
import sif.dd.au30.conversion.DataModelUnmarshalFactory;
27+
import sif.dd.au30.model.StudentPersonalCollectionType;
28+
import sif3.common.conversion.MarshalFactory;
29+
import sif3.common.conversion.UnmarshalFactory;
30+
import sif3.common.exception.ServiceInvokationException;
31+
import sif3.common.header.HeaderProperties;
32+
import sif3.common.header.HeaderValues.EventAction;
33+
import sif3.common.header.RequestHeaderConstants;
34+
import sif3.common.model.SIFEvent;
35+
import sif3.infra.common.env.mgr.BrokeredProviderEnvironmentManager;
36+
import sif3.infra.common.env.types.AdapterEnvironmentStore;
37+
import sif3.infra.common.env.types.ConsumerEnvironment.ConnectorName;
38+
import sif3.infra.rest.client.EventClient;
39+
import systemic.sif3.demo.rest.conversion.CSVMarshaller;
40+
import au.com.systemic.framework.utils.FileReaderWriter;
41+
42+
/**
43+
* @author Joerg Huber
44+
*
45+
*/
46+
public class TestEventClient
47+
{
48+
private final static String MULTI_STUDENT_FILE_NAME = "C:/Development/GitHubRepositories/SIF3InfraRest/SIF3InfraREST/TestData/xml/input/StudentPersonals5.xml";
49+
// private static final String PROP_FILE_NAME="BrokeredSISProvider";
50+
private static final String PROP_FILE_NAME="StudentProvider";
51+
52+
// Broker
53+
// private static final String EVENT_CONNECTOR_URI = "https://australia.hostedzone.com/svcs/systemicDemo/events";
54+
// private static final String SESSION_TOKEN = "1a47dae9-579b-4aa5-8048-608b06c611cb";
55+
// private static final String PWD="---";
56+
// private static final String ZONE="demo";
57+
58+
// private static final String EVENT_CONNECTOR_URI = "https://australia.hostedzone.com/svcs/systemicDemo/events";
59+
// private static final String SESSION_TOKEN = "be06a10e-1771-47c3-99bc-52a30b34711b";
60+
// private static final String PWD="---";
61+
// private static final String ZONE="loadZone";
62+
63+
// Local host setup
64+
private static final String EVENT_CONNECTOR_URI = "http://localhost:9080/SIF3InfraREST/sif3/eventsConnector";
65+
private static final String SESSION_TOKEN = "25745c93-07d3-4ca8-a28a-389084719cba";
66+
private static final String PWD="Password1";
67+
private static final String ZONE="auSchoolTestingZone";
68+
69+
70+
private MarshalFactory marshaller = new DataModelMarshalFactory();
71+
private UnmarshalFactory unmarshaller = new DataModelUnmarshalFactory();
72+
private AdapterEnvironmentStore store = new AdapterEnvironmentStore(PROP_FILE_NAME);
73+
74+
75+
private StudentPersonalCollectionType getStudents()
76+
{
77+
String inputEnvXML = FileReaderWriter.getFileContent(MULTI_STUDENT_FILE_NAME);
78+
//System.out.println("File content:\n" + inputEnvXML);
79+
try
80+
{
81+
return (StudentPersonalCollectionType)unmarshaller.unmarshalFromXML(inputEnvXML, StudentPersonalCollectionType.class);
82+
}
83+
catch (Exception ex)
84+
{
85+
ex.printStackTrace();
86+
return null;
87+
}
88+
}
89+
90+
// private SIFEvent<StudentCollectionType> getEvents()
91+
// {
92+
// SIFEvent<StudentCollectionType> events = new SIFEvent<StudentCollectionType>();
93+
// events.setEventAction(EventAction.UPDATE);
94+
// //events.setUpdateType(UpdateType.FULL); // If this is not set then the value from the property file should be used.
95+
// events.setSIFObjectList(getStudents());
96+
// events.setListSize(events.getSIFObjectList().getStudentPersonal().size());
97+
//
98+
// return events;
99+
// }
100+
101+
private SIFEvent<String> getEvents()
102+
{
103+
SIFEvent<String> events = new SIFEvent<String>();
104+
events.setEventAction(EventAction.UPDATE);
105+
//events.setUpdateType(UpdateType.FULL); // If this is not set then the value from the property file should be used.
106+
events.setSIFObjectList(new String("123,Peter,Hydon,1\n456,Dan,Carter,1\n890,Monica,Saladin,2"));
107+
events.setListSize(3);
108+
109+
return events;
110+
}
111+
112+
private URI getEventConnectorURI()
113+
{
114+
try
115+
{
116+
return new URI(EVENT_CONNECTOR_URI);
117+
}
118+
catch (Exception ex)
119+
{
120+
return null;
121+
}
122+
}
123+
124+
/*
125+
* Just fake a SIF3Session.
126+
*/
127+
// private SIF3Session getSIF3Session()
128+
// {
129+
// SIF3Session session = new SIF3Session();
130+
// session.setSessionToken(SESSION_TOKEN);
131+
// session.setPassword(PWD);
132+
// session.setDefaultZone(new SIFZone(ZONE, true));
133+
//
134+
// return session;
135+
// }
136+
137+
private EventClient getEventClient()
138+
{
139+
// store.getEnvironment().addConnectorBaseURI(ConnectorName.eventsConnector, getEventConnectorURI());
140+
// ProviderEnvironment env = (ProviderEnvironment)store.getEnvironment();
141+
142+
BrokeredProviderEnvironmentManager.getInstance().getEnvironmentInfo().addConnectorBaseURI(ConnectorName.eventsConnector, getEventConnectorURI());
143+
return new EventClient(BrokeredProviderEnvironmentManager.getInstance(), MediaType.TEXT_PLAIN_TYPE, MediaType.TEXT_PLAIN_TYPE, "CSVStudents", new CSVMarshaller(), false);
144+
// return new EventClient(env, env.getMediaType(), env.getMediaType(), getSIF3Session(), "StudentPersonals", marshaller);
145+
}
146+
147+
private void sendEvent(EventClient evtClt) throws ServiceInvokationException
148+
{
149+
System.out.println(evtClt.sendEvents(getEvents(), null, null, getOverrideHeaderProperties()));
150+
}
151+
152+
153+
private HeaderProperties getOverrideHeaderProperties()
154+
{
155+
HeaderProperties hdrProps = new HeaderProperties();
156+
hdrProps.setHeaderProperty(RequestHeaderConstants.HDR_GENERATOR_ID, "TestEventGenerator");
157+
hdrProps.setHeaderProperty(RequestHeaderConstants.HDR_APPLICATION_KEY, "TestEventClient");
158+
hdrProps.setHeaderProperty(RequestHeaderConstants.HDR_AUTHENTICATED_USER, "");
159+
160+
return hdrProps;
161+
}
162+
163+
public static void main(String[] args)
164+
{
165+
try
166+
{
167+
TestEventClient tester = new TestEventClient();
168+
169+
System.out.println("Start Testing TestEventClient...");
170+
171+
EventClient evtClt = tester.getEventClient();
172+
for (int i=0; i<5; i++)
173+
{
174+
tester.sendEvent(evtClt);
175+
}
176+
177+
System.out.println("End Testing TestEventClient.");
178+
}
179+
catch (Exception ex)
180+
{
181+
ex.printStackTrace();
182+
}
183+
}
184+
}
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
/*
2+
* TestStudentPersonalConsumer.java Created: 24/09/2013
3+
*
4+
* Copyright 2013 Systemic Pty Ltd
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
7+
* in compliance with the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software distributed under the License
12+
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
13+
* or implied. See the License for the specific language governing permissions and limitations under
14+
* the License.
15+
*/
16+
17+
package sif3.test.infra.rest.consumer;
18+
19+
import java.util.List;
20+
21+
import javax.ws.rs.core.MediaType;
22+
23+
import sif3.common.ws.Response;
24+
import sif3.infra.rest.consumer.ConsumerLoader;
25+
import systemic.sif3.demo.rest.consumer.CSVStudentConsumer;
26+
import systemic.sif3.demo.rest.conversion.CSVUnmarshaller;
27+
import au.com.systemic.framework.utils.FileReaderWriter;
28+
29+
/**
30+
* @author Joerg Huber
31+
*
32+
*/
33+
public class TestCSVStudentConsumer
34+
{
35+
// private final static String PATH = "/Users/crub/dev/nsip/Users/crub/dev/nsip/sif3-framework-java-dev";
36+
private final static String PATH = "C:/DEV/eclipseWorkspace";
37+
// private final static String PATH = "C:/Development/GitHubRepositories/SIF3InfraRest";
38+
39+
private final static String CSV_FILE_NAME = PATH + "/SIF3InfraREST/TestData/csv/input/CSVStudents.csv";
40+
private static final String CONSUMER_ID = "StudentConsumer";
41+
42+
private void printResponses(List<Response> responses, CSVStudentConsumer consumer)
43+
{
44+
try
45+
{
46+
if (responses != null)
47+
{
48+
int i = 1;
49+
for (Response response : responses)
50+
{
51+
System.out.println("Response "+i+":\n"+response);
52+
if (response.hasError())
53+
{
54+
System.out.println("Error for Response "+i+": "+response.getError());
55+
}
56+
else // We should have a student personal
57+
{
58+
if (response.getHasEntity())
59+
{
60+
System.out.println("Data Object Response "+i+": "+consumer.getMarshaller().marshal(response.getDataObject(), consumer.getResponseMediaType()));
61+
}
62+
else
63+
{
64+
System.out.println("Data Object Response "+i+": No Data Returned. Respnse Status = "+response.getStatus()+" ("+response.getStatusMessage()+")");
65+
}
66+
}
67+
i++;
68+
}
69+
}
70+
else
71+
{
72+
System.out.println("Responses from attempt to create Student: null");
73+
}
74+
}
75+
catch (Exception ex)
76+
{
77+
ex.printStackTrace();
78+
}
79+
}
80+
81+
private String getCSV(CSVUnmarshaller unmarshaller)
82+
{
83+
String inputData = FileReaderWriter.getFileContent(CSV_FILE_NAME);
84+
System.out.println("File content:\n" + inputData);
85+
try
86+
{
87+
return (String)unmarshaller.unmarshal(inputData, String.class, MediaType.TEXT_PLAIN_TYPE);
88+
}
89+
catch (Exception ex)
90+
{
91+
ex.printStackTrace();
92+
return null;
93+
}
94+
}
95+
96+
private void createCSV(CSVStudentConsumer consumer)
97+
{
98+
System.out.println("Start 'Create CSV' in all connected environments...");
99+
String csvData = getCSV((CSVUnmarshaller)consumer.getUnmarshaller());
100+
try
101+
{
102+
List<Response> responses = consumer.createSingle(csvData, null);
103+
System.out.println("Responses from attempt to Create CSV:");
104+
printResponses(responses, consumer);
105+
}
106+
catch (Exception ex)
107+
{
108+
ex.printStackTrace();
109+
}
110+
System.out.println("Finished 'Create CSV' in all connected environments...");
111+
}
112+
113+
private CSVStudentConsumer getConsumer()
114+
{
115+
return new CSVStudentConsumer();
116+
}
117+
118+
public static void main(String[] args)
119+
{
120+
TestCSVStudentConsumer tester = new TestCSVStudentConsumer();
121+
System.out.println("Start Testing CSVStudentConsumer...");
122+
123+
if (ConsumerLoader.initialise(CONSUMER_ID))
124+
{
125+
CSVStudentConsumer consumer = tester.getConsumer();
126+
127+
//tester.createCSV(consumer);
128+
129+
System.out.println("Finalise Consumer (i.e. disconnect and remove environment).");
130+
consumer.finalise();
131+
}
132+
133+
ConsumerLoader.shutdown();
134+
System.out.println("End Testing CSVStudentConsumer.");
135+
}
136+
137+
}

0 commit comments

Comments
 (0)