25
25
import java .util .List ;
26
26
import java .util .Map ;
27
27
import java .util .Set ;
28
+
29
+ import org .jboss .arquillian .config .descriptor .api .ContainerDef ;
30
+ import org .jboss .arquillian .config .descriptor .api .ProtocolDef ;
28
31
import org .jboss .arquillian .config .descriptor .impl .ContainerDefImpl ;
29
32
import org .jboss .arquillian .container .impl .LocalContainerRegistry ;
30
33
import org .jboss .arquillian .container .spi .Container ;
44
47
import org .jboss .arquillian .container .test .spi .client .deployment .AuxiliaryArchiveProcessor ;
45
48
import org .jboss .arquillian .container .test .spi .client .deployment .DeploymentPackager ;
46
49
import org .jboss .arquillian .container .test .spi .client .deployment .DeploymentScenarioGenerator ;
50
+ import org .jboss .arquillian .container .test .spi .client .deployment .ProtocolArchiveProcessor ;
47
51
import org .jboss .arquillian .container .test .spi .client .protocol .Protocol ;
52
+ import org .jboss .arquillian .container .test .spi .client .protocol .ProtocolConfiguration ;
48
53
import org .jboss .arquillian .container .test .test .AbstractContainerTestTestBase ;
49
54
import org .jboss .arquillian .core .api .Injector ;
50
55
import org .jboss .arquillian .core .api .Instance ;
@@ -137,6 +142,41 @@ public void shouldUseDefaultDefinedProtocolIfFound() {
137
142
verify (deployableContainer , times (0 )).getDefaultProtocol ();
138
143
}
139
144
145
+ @ Test
146
+ public void shouldUseContainerProtocolIfFound () {
147
+ Container container = addContainer ("test-contianer-with-protocol" );
148
+ ContainerDef containerDef = container .getContainerConfiguration ();
149
+ containerDef .setMode ("suite" );
150
+ AltDeploymentPackager packager1 = new AltDeploymentPackager ();
151
+ addProtocolWithPackager (PROTOCOL_NAME_1 , false , packager1 , Collections .singletonMap ("mode" , "default" ));
152
+ // Now add a container local protocol with a custom config
153
+ ProtocolDef protocolDef = containerDef .protocol (PROTOCOL_NAME_1 )
154
+ .property ("mode" , "custom" );
155
+
156
+ fire (createEvent (DeploymentWithProtocol .class ));
157
+
158
+ verify (deployableContainer , times (0 )).getDefaultProtocol ();
159
+ TheProtocolConfiguration config = (TheProtocolConfiguration ) packager1 .getConfig ();
160
+ Assert .assertEquals ("custom" , config .getMode ());
161
+ }
162
+ @ Test
163
+ public void shouldUseContainerDefaultProtocolIfFound () {
164
+ Container container = addContainer ("test-contianer-with-protocol" );
165
+ ContainerDef containerDef = container .getContainerConfiguration ();
166
+ containerDef .setMode ("suite" );
167
+ AltDeploymentPackager packager1 = new AltDeploymentPackager ();
168
+ addProtocolWithPackager (PROTOCOL_NAME_1 , true , packager1 , Collections .singletonMap ("mode" , "default" ));
169
+ // Now add a container local protocol with a custom config
170
+ ProtocolDef protocolDef = containerDef .protocol (PROTOCOL_NAME_1 )
171
+ .property ("mode" , "custom" );
172
+
173
+ fire (createEvent (DeploymentWithDefaults .class ));
174
+
175
+ verify (deployableContainer , times (0 )).getDefaultProtocol ();
176
+ TheProtocolConfiguration config = (TheProtocolConfiguration ) packager1 .getConfig ();
177
+ Assert .assertEquals ("custom" , config .getMode ());
178
+ }
179
+
140
180
@ Test
141
181
public void shouldAddAdditionalObserverClasses () {
142
182
addContainer ("test-contianer" ).getContainerConfiguration ().setMode ("suite" );
@@ -339,14 +379,25 @@ private Container addContainer(String name) {
339
379
}
340
380
341
381
private ProtocolDefinition addProtocol (String name , boolean shouldBeDefault ) {
342
- Protocol <? > protocol = mock (Protocol .class );
382
+ Protocol <TheProtocolConfiguration > protocol = mock (Protocol .class );
343
383
when (protocol .getPackager ()).thenReturn (packager );
344
384
when (protocol .getDescription ()).thenReturn (new ProtocolDescription (name ));
385
+ when (protocol .getProtocolConfigurationClass ()).thenReturn (TheProtocolConfiguration .class );
345
386
346
387
Map <String , String > config = Collections .emptyMap ();
347
388
return protocolRegistry .addProtocol (new ProtocolDefinition (protocol , config , shouldBeDefault ))
348
389
.getProtocol (new ProtocolDescription (name ));
349
390
}
391
+ private ProtocolDefinition addProtocolWithPackager (String name , boolean shouldBeDefault ,
392
+ DeploymentPackager packager , Map <String , String > config ) {
393
+ Protocol <TheProtocolConfiguration > protocol = mock (Protocol .class );
394
+ when (protocol .getPackager ()).thenReturn (packager );
395
+ when (protocol .getDescription ()).thenReturn (new ProtocolDescription (name ));
396
+ when (protocol .getProtocolConfigurationClass ()).thenReturn (TheProtocolConfiguration .class );
397
+
398
+ return protocolRegistry .addProtocol (new ProtocolDefinition (protocol , config , shouldBeDefault ))
399
+ .getProtocol (new ProtocolDescription (name ));
400
+ }
350
401
351
402
private <T > Collection <T > create (Class <T > type , T ... instances ) {
352
403
List <T > list = new ArrayList <T >();
@@ -365,6 +416,15 @@ public static JavaArchive deploy() {
365
416
return ShrinkWrap .create (JavaArchive .class );
366
417
}
367
418
}
419
+ private static class DeploymentWithProtocol {
420
+ @ SuppressWarnings ("unused" )
421
+ @ Deployment
422
+ @ OverProtocol (PROTOCOL_NAME_1 )
423
+ public static JavaArchive deploy () {
424
+ return ShrinkWrap .create (JavaArchive .class );
425
+ }
426
+ }
427
+
368
428
369
429
@ Observer ({ObserverClass .class , SecondObserverClass .class })
370
430
private static class DeploymentWithObserver {
@@ -519,4 +579,26 @@ public void process(Archive<?> applicationArchive, TestClass testClass) {
519
579
called ();
520
580
}
521
581
}
582
+
583
+ public static class TheProtocolConfiguration implements ProtocolConfiguration {
584
+ private String mode ;
585
+
586
+ public String getMode () {
587
+ return mode ;
588
+ }
589
+ public void setMode (String mode ) {
590
+ this .mode = mode ;
591
+ }
592
+ }
593
+ private static class AltDeploymentPackager implements DeploymentPackager {
594
+ private ProtocolConfiguration config = null ;
595
+ @ Override
596
+ public Archive <?> generateDeployment (TestDeployment testDeployment , Collection <ProtocolArchiveProcessor > processors ) {
597
+ config = testDeployment .getProtocolConfiguration ();
598
+ return testDeployment .getApplicationArchive ();
599
+ }
600
+ public ProtocolConfiguration getConfig () {
601
+ return config ;
602
+ }
603
+ }
522
604
}
0 commit comments