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 org.apache.log4j.Logger;
40 import org.ggf.schemas.jsdl.x2005.x11.jsdl.JobDescriptionDocument;
41 import org.ggf.schemas.jsdl.x2005.x11.jsdl.JobDescriptionType;
42 import org.ogf.graap.wsag.api.AgreementOffer;
43 import org.ogf.graap.wsag.api.client.AgreementClient;
44 import org.ogf.graap.wsag.api.client.AgreementFactoryClient;
45 import org.ogf.graap.wsag.api.client.AgreementFactoryRegistryClient;
46 import org.ogf.graap.wsag.api.exceptions.AgreementFactoryException;
47 import org.ogf.graap.wsag.api.exceptions.ResourceUnavailableException;
48 import org.ogf.graap.wsag.api.exceptions.ResourceUnknownException;
49 import org.ogf.graap.wsag.api.security.SecurityProperties;
50 import org.ogf.graap.wsag.api.types.AgreementOfferType;
51 import org.ogf.graap.wsag.client.AgreementFactoryRegistryLocator;
52 import org.ogf.graap.wsag.client.remote.RemoteAgreementFactoryClientImpl;
53 import org.ogf.schemas.graap.wsAgreement.AgreementTemplateType;
54 import org.ogf.schemas.graap.wsAgreement.GuaranteeTermStateDefinition;
55 import org.ogf.schemas.graap.wsAgreement.GuaranteeTermStateType;
56 import org.ogf.schemas.graap.wsAgreement.ServiceDescriptionTermType;
57 import org.w3.x2005.x08.addressing.EndpointReferenceDocument;
58 import org.w3.x2005.x08.addressing.EndpointReferenceType;
59
60
61
62
63
64
65
66 public abstract class AbstractAgreementFactoryTest extends AbstractIntegrationTest
67 {
68
69 private static final Logger LOG = Logger.getLogger( AbstractAgreementFactoryTest.class );
70
71
72
73
74
75 public AbstractAgreementFactoryTest( String name )
76 {
77 super( name );
78 }
79
80
81
82
83 public void testCreateDestroyAgreement()
84 {
85 try
86 {
87 LOG.info( "Entering TestCase: testCreateDestroyAgreement" );
88
89 AgreementFactoryClient[] factories = getAgreementFactoryClients();
90 assertEquals( EXPECTED_FACTORIES, factories.length );
91
92 AgreementFactoryClient factory = factories[0];
93
94 AgreementClient[] agreements;
95
96
97
98
99
100
101
102
103
104
105
106 LOG.info( "Creating new Agreements" );
107 AgreementTemplateType[] templates = factory.getTemplates();
108 AgreementOffer offer = new AgreementOfferType( templates[0] );
109
110 LOG.info( "Create agreement 1" );
111 AgreementClient agreement1 = factory.createAgreement( offer );
112
113 assertNotNull( "the created agreement must not be <null>", agreement1 );
114
115 agreements = factory.listAgreements();
116 assertEquals( 1, agreements.length );
117
118 LOG.info( "Create agreement 2" );
119 AgreementClient agreement2 = factory.createAgreement( offer );
120 assertNotNull( "the created agreement must not be <null>", agreement2 );
121
122 LOG.info( "List agreements" );
123 agreements = factory.listAgreements();
124 assertEquals( 2, agreements.length );
125
126 LOG.info( "Destroy agreement 1" );
127 agreement1.destroy();
128 agreements = factory.listAgreements();
129 assertEquals( 1, agreements.length );
130
131 LOG.info( "Destroy agreement 2" );
132 agreement2.destroy();
133 agreements = factory.listAgreements();
134 assertEquals( 0, agreements.length );
135 }
136 catch ( AgreementFactoryException e )
137 {
138 fail( "AgreementFactoryException: " + e.getMessage() );
139 }
140 catch ( ResourceUnavailableException e )
141 {
142 fail( "ResourceUnavailableException: " + e.getMessage() );
143 }
144 catch ( ResourceUnknownException e )
145 {
146 fail( "ResourceUnknownException: " + e.getMessage() );
147 }
148 catch ( Exception e )
149 {
150 fail( "Could not create agreement factory instance. Error: " + e.getMessage() );
151 }
152 }
153
154
155
156
157
158
159
160 public void testGetTemplate() throws Exception
161 {
162 LOG.info( "Entering TestCase: testGetTemplate" );
163
164
165 AgreementFactoryClient[] factories = getAgreementFactoryClients();
166 assertEquals( EXPECTED_FACTORIES, factories.length );
167
168
169
170
171 AgreementFactoryClient factory = null;
172 for ( int i = 0; i < factories.length; i++ )
173 {
174 AgreementTemplateType[] templates = factories[i].getTemplates();
175
176 assertNotNull( templates );
177
178 if ( templates.length == EXPECTED_TEMPLATES_FACTORY_1 )
179 {
180 factory = factories[i];
181 }
182 }
183
184 assertNotNull( factory );
185
186
187
188 AgreementTemplateType[] templates = factory.getTemplates();
189
190
191 assertNotNull( "check that the call returned a template array", templates );
192
193 assertEquals( "check that the call returned exactly " + EXPECTED_TEMPLATES_FACTORY_1 + " templates",
194 EXPECTED_TEMPLATES_FACTORY_1, templates.length );
195
196
197
198
199
200 assertEquals( "check that the name of the 1. template equals \"SAMPLE1\"", "SAMPLE1",
201 templates[0].getName() );
202 assertEquals( "check that the id of the 1. template equals \"1\"", "1", templates[0].getTemplateId() );
203 assertEquals( "check that the name of the 2. template equals \"SAMPLE2\"", "SAMPLE2",
204 templates[1].getName() );
205 assertEquals( "check that the agreement id of the 2. template equals \"2\"", "2",
206 templates[1].getTemplateId() );
207 assertEquals( "check that the name of the 1. template equals \"sample_service_description_term\"",
208 "SAMPLE1_SDT",
209 templates[0].getTerms().getAll().getServiceDescriptionTermArray( 0 ).getName() );
210 assertEquals( "check that the service name of the 1. template equals \"sample_service\"",
211 "SAMPLE1_SERVICE",
212 templates[0].getTerms().getAll().getServiceDescriptionTermArray( 0 ).getServiceName() );
213
214 }
215
216
217
218
219
220
221
222 public void testCreateAgreement() throws Exception
223 {
224 LOG.info( "Entering TestCase: testCreateAgreement" );
225
226
227
228 AgreementFactoryClient[] factories = getAgreementFactoryClients();
229 assertEquals( EXPECTED_FACTORIES, factories.length );
230
231
232
233
234 AgreementFactoryClient factory = null;
235 for ( int i = 0; i < factories.length; i++ )
236 {
237 if ( "SAMPLE-INSTANCE-1".equals( factories[i].getResourceId() ) )
238 {
239 factory = factories[i];
240 break;
241 }
242 }
243
244
245
246
247 AgreementTemplateType template = factory.getTemplate( "SAMPLE1", "1" );
248
249
250
251
252
253 AgreementOffer offer = new AgreementOfferType( template );
254
255
256
257
258 ServiceDescriptionTermType sdt = offer.getTerms().getAll().getServiceDescriptionTermArray( 0 );
259
260
261
262
263
264
265
266 JobDescriptionType job =
267 (JobDescriptionType) sdt.selectChildren( JobDescriptionDocument.type.getDocumentElementName() )[0];
268
269
270
271
272 job.getResources().addNewIndividualCPUCount().addNewExact().setDoubleValue( 4 );
273
274
275
276
277
278
279
280 AgreementClient agreement = factory.createAgreement( offer );
281
282
283
284 assertNotNull( "the created agreement must not be <null>", agreement );
285
286 GuaranteeTermStateType[] guaranteeTermStates = agreement.getGuaranteeTermStates();
287 assertEquals( "the number of guarantee term states must be <2>", guaranteeTermStates.length, 2 );
288
289 assertEquals( "term_0", guaranteeTermStates[0].getTermName() );
290 assertEquals( "term_1", guaranteeTermStates[1].getTermName() );
291
292 assertEquals( GuaranteeTermStateDefinition.INT_NOT_DETERMINED,
293 guaranteeTermStates[0].getState().intValue() );
294 assertEquals( GuaranteeTermStateDefinition.INT_FULFILLED,
295 guaranteeTermStates[1].getState().intValue() );
296
297 agreement.destroy();
298 }
299
300
301
302
303
304
305
306 public void testCreateTerminateAgreement() throws Exception
307 {
308 LOG.info( "Entering TestCase: testCreateTerminateAgreement" );
309
310 AgreementFactoryClient[] factories = getAgreementFactoryClients();
311 assertEquals( EXPECTED_FACTORIES, factories.length );
312
313 for ( int i = 0; i < 2; i++ )
314 {
315 LOG.warn( "+ " + factories[i].getResourceId() );
316 LOG.warn( " + Number of templates: " + factories[i].getTemplates().length );
317 }
318
319 AgreementFactoryClient factory = factories[1];
320 AgreementTemplateType[] templates = factory.getTemplates();
321
322 AgreementOffer offer = new AgreementOfferType( templates[0] );
323 AgreementClient agreement = factory.createAgreement( offer );
324 assertNotNull( agreement );
325
326
327
328
329
330 agreement.destroy();
331 }
332
333
334
335
336
337
338
339
340 public void testCreateAgreementException() throws Exception
341 {
342 LOG.info( "Entering TestCase: testCreateAgreementException" );
343
344 AgreementFactoryClient[] factories = getAgreementFactoryClients();
345 assertEquals( EXPECTED_FACTORIES, factories.length );
346
347 AgreementFactoryClient factory = factories[0];
348 AgreementTemplateType[] templates = factory.getTemplates();
349
350 AgreementOffer offer = new AgreementOfferType( templates[0] );
351 offer.getTerms().getAll().getServiceDescriptionTermArray( 0 ).setName( "TEST_EXCEPTION" );
352
353
354 AgreementClient agreement = null;
355 AgreementFactoryException exception = null;
356 try
357 {
358 agreement = factory.createAgreement( offer );
359 }
360 catch ( AgreementFactoryException e )
361 {
362 exception = e;
363 }
364
365
366 assertNull( agreement );
367 assertNotNull( exception );
368 }
369
370
371
372
373
374
375
376
377
378
379 public void testGetFactoryClientURL()
380 {
381 EndpointReferenceType epr = EndpointReferenceType.Factory.newInstance();
382 epr.addNewAddress().setStringValue( getUrl() + "/" );
383
384 AgreementFactoryRegistryClient registry = null;
385 AgreementFactoryClient[] factories = null;
386
387 try
388 {
389 registry = AgreementFactoryRegistryLocator.getFactoryRegistry( epr, getLoginContext() );
390 factories = registry.listAgreementFactories();
391 assertEquals( EXPECTED_FACTORIES, factories.length );
392 }
393 catch ( Exception ex )
394 {
395 fail( "Failed to initialize factory list (BUG 79). " + ex.getMessage() );
396 }
397
398 try
399 {
400 AgreementTemplateType[] templates = factories[0].getTemplates();
401 assertTrue( templates.length > 0 );
402
403 }
404 catch ( Exception ex )
405 {
406 fail( "Failed to list agreement templates (BUG 79). " + ex.getMessage() );
407 }
408 }
409
410
411
412
413
414
415
416 public void testResourceUnknown() throws Exception
417 {
418
419 System.out.println( "Test ResourceUnknownFault." );
420
421 String eprText =
422 "<wsa:EndpointReference xmlns:wsa=\"http://www.w3.org/2005/08/addressing\">"
423 + "<wsa:Address xmlns:wsa=\"http://www.w3.org/2005/08/addressing\">{0}{1}</wsa:Address>"
424 + "<wsa:ReferenceParameters xmlns:wsa=\"http://www.w3.org/2005/08/addressing\">"
425 + "<ResourceId xmlns=\"http://schemas.scai.fraunhofer.de/wsag4j\">WSAG4J_ResourceId-43</ResourceId>"
426 + "</wsa:ReferenceParameters><Metadata xmlns=\"http://www.w3.org/2005/08/addressing\">"
427 + "<ServerIdentity xmlns=\"http://schemas.scai.fraunhofer.de/2008/11/wsag4j/engine\">"
428 + "1.2.840.113549.1.9.1=#16236f6c697665722e7761656c647269636840736361692e667261756e686f6665722e6465,"
429 + "CN=wsag4j-server,OU=WSAG4J,O=Fraunhofer SCAI/bio,ST=NRW,C=DE</ServerIdentity>"
430 + "</Metadata></wsa:EndpointReference>";
431
432 Object[] filler = new Object[] { getUrl(), "/services/AgreementFactory" };
433 String eprXML = MessageFormat.format( eprText, filler );
434 EndpointReferenceType epr = EndpointReferenceDocument.Factory.parse( eprXML ).getEndpointReference();
435
436 AgreementFactoryClient client =
437 new RemoteAgreementFactoryClientImpl( epr, new SecurityProperties( getLoginContext() ) );
438
439 boolean exceptionReceived = false;
440
441 try
442 {
443 LOG.info( "Invoking GetTemplates on an unknown resource should throw a ResourceUnknownFault." );
444 client.getTemplates();
445 }
446 catch ( ResourceUnknownException e )
447 {
448 exceptionReceived = true;
449 LOG.info( "ResourceUnknownFault received" );
450 }
451
452 assertTrue( "ResourceUnknownFault was not received.", exceptionReceived );
453 }
454
455 }