1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35 package org.ogf.graap.wsag.it;
36
37 import java.text.MessageFormat;
38
39 import javax.security.auth.login.LoginContext;
40
41 import junit.framework.Assert;
42
43 import org.apache.log4j.Logger;
44 import org.ogf.graap.wsag.api.security.KeystoreLoginContext;
45 import org.ogf.graap.wsag.api.security.KeystoreProperties;
46 import org.ogf.graap.wsag.client.api.AgreementClient;
47 import org.ogf.graap.wsag.client.api.AgreementFactoryClient;
48 import org.ogf.graap.wsag.client.api.AgreementFactoryRegistryClient;
49 import org.w3.x2005.x08.addressing.EndpointReferenceType;
50
51
52
53
54
55
56
57
58
59 public abstract class AbstractIntegrationTest extends WsagTestCase
60 {
61
62 private static final Logger LOG = Logger.getLogger( AbstractIntegrationTest.class );
63
64
65
66
67 private static String url = "http://127.0.0.1:8080/wsag4j";
68
69
70
71
72 public static String getUrl()
73 {
74 return url;
75 }
76
77
78
79
80
81 public static void setUrl( String url )
82 {
83 AbstractIntegrationTest.url = url;
84 }
85
86
87
88
89 private static final int EXPECTED_FACTORIES = 1;
90
91
92
93
94 public static final int EXPECTED_TEMPLATES_FACTORY_1 = 6;
95
96
97
98
99 public static final int EXPECTED_TEMPLATES_FACTORY_2 = 2;
100
101 static
102 {
103 String gatewayURL = System.getProperty( "wsag4j.gateway.address" );
104 if ( gatewayURL != null )
105 {
106 LOG.info( "Gateway address was set via SystemPorperties: " + gatewayURL );
107 url = gatewayURL;
108 }
109 else
110 {
111 LOG.info( "Gateway address was not set via SystemPorperties." );
112 }
113 }
114
115
116
117
118
119 protected AbstractIntegrationTest( String name )
120 {
121 super( name );
122 }
123
124
125
126
127
128
129
130 @Override
131 protected void setUp() throws Exception
132 {
133 super.setUp();
134
135 EndpointReferenceType epr = EndpointReferenceType.Factory.newInstance();
136 epr.addNewAddress().setStringValue( url );
137
138 AgreementFactoryRegistryClient registry = null;
139 AgreementFactoryClient[] factories = null;
140
141 try
142 {
143 registry = AgreementFactoryRegistryClient.FACTORY.newInstance( epr, getLoginContext() );
144 factories = registry.listAgreementFactories();
145 }
146 catch ( Exception ex )
147 {
148 Assert.fail( "Failed to initialize factory list. " + ex.getMessage() );
149 }
150
151
152
153
154 try
155 {
156 for ( int i = 0; i < factories.length; i++ )
157 {
158 AgreementClient[] agreements = factories[i].listAgreements();
159 for ( int j = 0; j < agreements.length; j++ )
160 {
161 agreements[j].destroy();
162 }
163 }
164 }
165 catch ( Exception e )
166 {
167 String message =
168 MessageFormat.format( "Error while cleaning up existing agreement resources. Error: {0}",
169 new Object[] { e.getMessage() } );
170 LOG.error( message );
171 throw e;
172 }
173 }
174
175
176
177
178 @Override
179 protected void tearDown() throws Exception
180 {
181 super.tearDown();
182 }
183
184
185
186
187
188 public static AgreementFactoryClient[] getAgreementFactoryClients()
189 {
190 AgreementFactoryClient[] factories = null;
191 try
192 {
193
194 LoginContext loginContext = AbstractIntegrationTest.getLoginContext();
195
196
197 EndpointReferenceType epr = EndpointReferenceType.Factory.newInstance();
198 epr.addNewAddress().setStringValue( AbstractIntegrationTest.url );
199
200 AgreementFactoryRegistryClient registry =
201 AgreementFactoryRegistryClient.FACTORY.newInstance( epr, loginContext );
202 factories = registry.listAgreementFactories();
203
204 }
205 catch ( Exception ex )
206 {
207 LOG.error( ex );
208 }
209
210 return factories;
211 }
212
213
214
215
216
217
218
219
220
221 public static AgreementFactoryClient getAgreementFactoryClient( String id )
222 {
223 AgreementFactoryClient factory = null;
224 try
225 {
226
227 LoginContext loginContext = AbstractIntegrationTest.getLoginContext();
228
229
230 EndpointReferenceType epr = EndpointReferenceType.Factory.newInstance();
231 epr.addNewAddress().setStringValue( AbstractIntegrationTest.url );
232
233 AgreementFactoryRegistryClient registry =
234 AgreementFactoryRegistryClient.FACTORY.newInstance( epr, loginContext );
235 factory = registry.getFactory( id );
236
237
238 assertNotNull( "requested factory does not exist", factory );
239 }
240 catch ( Exception ex )
241 {
242 LOG.error( ex );
243 }
244
245 return factory;
246 }
247
248
249
250
251
252
253
254 public static LoginContext getLoginContext() throws Exception
255 {
256
257
258
259 LOG.info( "Create Keystore-LoginContext" );
260
261
262 KeystoreProperties properties = new KeystoreProperties();
263 properties.setKeyStoreAlias( "wsag4j-user" );
264 properties.setPrivateKeyPassword( "user@wsag4j" );
265
266 properties.setKeyStoreType( "JKS" );
267 properties.setKeystoreFilename( "/wsag4j-client-keystore.jks" );
268 properties.setKeystorePassword( "user@wsag4j" );
269
270 properties.setTruststoreType( "JKS" );
271 properties.setTruststoreFilename( "/wsag4j-client-keystore.jks" );
272 properties.setTruststorePassword( "user@wsag4j" );
273
274 LoginContext loginContext = new KeystoreLoginContext( properties );
275 loginContext.login();
276
277
278 return loginContext;
279 }
280
281
282
283
284
285
286 public int getDefaultFactoryCount()
287 {
288 return EXPECTED_FACTORIES;
289 }
290 }