|
42 | 42 |
|
43 | 43 | public class TckArquillianDeployListener {
|
44 | 44 |
|
45 |
| - private final TckContainer tckContainer; |
| 45 | + private final TckContainer tckContainer; |
46 | 46 |
|
47 |
| - private final Map<Class<?>, List<DeploymentDescription>> activeDeployments = new ConcurrentHashMap<>(); |
| 47 | + private final Map<Class<?>, List<DeploymentDescription>> activeDeployments = new ConcurrentHashMap<>(); |
48 | 48 |
|
49 |
| - private final Archive<?> frameworkClasses = ShrinkWrap.create(JavaArchive.class) |
50 |
| - .addPackage(TckMessagingManager.class.getPackage().getName()); |
| 49 | + private final Archive<?> frameworkClasses = ShrinkWrap.create(JavaArchive.class) |
| 50 | + .addPackage(TckMessagingManager.class.getPackage().getName()); |
51 | 51 |
|
52 |
| - private final Archive<?> frameworkArchive = ShrinkWrap.create(JavaArchive.class) |
53 |
| - .addPackage(TckMessagingManager.class.getPackage().getName()) |
54 |
| - .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml"); |
| 52 | + private final Archive<?> frameworkArchive = ShrinkWrap.create(JavaArchive.class) |
| 53 | + .addPackage(TckMessagingManager.class.getPackage().getName()) |
| 54 | + .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml"); |
55 | 55 |
|
56 | 56 |
|
57 |
| - public TckArquillianDeployListener() { |
58 |
| - Iterator<TckContainer> containers = ServiceLoader.load(TckContainer.class).iterator(); |
| 57 | + public TckArquillianDeployListener() { |
| 58 | + Iterator<TckContainer> containers = ServiceLoader.load(TckContainer.class).iterator(); |
59 | 59 |
|
60 |
| - if (containers.hasNext()) { |
61 |
| - this.tckContainer = containers.next(); |
| 60 | + if (containers.hasNext()) { |
| 61 | + this.tckContainer = containers.next(); |
| 62 | + } |
| 63 | + else { |
| 64 | + throw new RuntimeException("No " + TckContainer.class.getName() + |
| 65 | + " found. To run this TCK, you must provide an implementation of " + |
| 66 | + TckContainer.class + " via the JDK service loader mechanism."); |
| 67 | + } |
62 | 68 | }
|
63 |
| - else { |
64 |
| - throw new RuntimeException("No " + TckContainer.class.getName() + |
65 |
| - " found. To run this TCK, you must provide an implementation of " + |
66 |
| - TckContainer.class + " via the JDK service loader mechanism."); |
67 |
| - } |
68 |
| - } |
69 |
| - |
70 |
| - public void onBeforeDeploy(@Observes BeforeDeploy beforeDeploy, TestClass testClass) throws DeploymentException { |
71 |
| - |
72 |
| - String[] topicNames = getTopicsUsedByTestClass(testClass); |
73 |
| - |
74 |
| - DeployableContainer<?> container = beforeDeploy.getDeployableContainer(); |
75 |
| - DeploymentDescription description = beforeDeploy.getDeployment(); |
76 |
| - |
77 |
| - List<DeploymentDescription> deployed = new ArrayList<>(); |
78 |
| - activeDeployments.put(testClass.getJavaClass(), deployed); |
79 | 69 |
|
80 |
| - List<DeploymentDescription> deployments = tckContainer.createDeployments(topicNames); |
81 |
| - for (DeploymentDescription deployable: deployments) { |
82 |
| - if (!tckContainer.mergeArchives() || deployable.isDescriptorDeployment() || description.isDescriptorDeployment()) { |
83 |
| - deployed.add(deployable); |
84 |
| - container.deploy(deployable.getDescriptor()); |
85 |
| - } |
86 |
| - else { |
87 |
| - description.getArchive().merge(deployable.getArchive()); |
88 |
| - } |
| 70 | + public void onBeforeDeploy(@Observes BeforeDeploy beforeDeploy, TestClass testClass) throws DeploymentException { |
| 71 | + |
| 72 | + String[] topicNames = getTopicsUsedByTestClass(testClass); |
| 73 | + |
| 74 | + DeployableContainer<?> container = beforeDeploy.getDeployableContainer(); |
| 75 | + DeploymentDescription description = beforeDeploy.getDeployment(); |
| 76 | + |
| 77 | + List<DeploymentDescription> deployed = new ArrayList<>(); |
| 78 | + activeDeployments.put(testClass.getJavaClass(), deployed); |
| 79 | + |
| 80 | + List<DeploymentDescription> deployments = tckContainer.createDeployments(topicNames); |
| 81 | + for (DeploymentDescription deployable : deployments) { |
| 82 | + if (!tckContainer.mergeArchives() || deployable.isDescriptorDeployment() || description.isDescriptorDeployment()) { |
| 83 | + deployed.add(deployable); |
| 84 | + container.deploy(deployable.getDescriptor()); |
| 85 | + } |
| 86 | + else { |
| 87 | + description.getArchive().merge(deployable.getArchive()); |
| 88 | + } |
| 89 | + } |
| 90 | + |
| 91 | + if (description.isArchiveDeployment()) { |
| 92 | + description.getArchive().merge(frameworkClasses); |
| 93 | + } |
| 94 | + else { |
| 95 | + deployed.add(new DeploymentDescription("reactive-messaging-tck-framework.jar", frameworkArchive)); |
| 96 | + container.deploy(frameworkArchive); |
| 97 | + } |
89 | 98 | }
|
90 | 99 |
|
91 |
| - if (description.isArchiveDeployment()) { |
92 |
| - description.getArchive().merge(frameworkClasses); |
93 |
| - } |
94 |
| - else { |
95 |
| - deployed.add(new DeploymentDescription("reactive-messaging-tck-framework.jar", frameworkArchive)); |
96 |
| - container.deploy(frameworkArchive); |
97 |
| - } |
98 |
| - } |
| 100 | + public void onAfterUnDeploy(@Observes AfterUnDeploy afterUnDeploy, TestClass testClass) throws DeploymentException { |
99 | 101 |
|
100 |
| - public void onAfterUnDeploy(@Observes AfterUnDeploy afterUnDeploy, TestClass testClass) throws DeploymentException { |
| 102 | + String[] topicNames = getTopicsUsedByTestClass(testClass); |
101 | 103 |
|
102 |
| - String[] topicNames = getTopicsUsedByTestClass(testClass); |
| 104 | + DeployableContainer<?> container = afterUnDeploy.getDeployableContainer(); |
103 | 105 |
|
104 |
| - DeployableContainer<?> container = afterUnDeploy.getDeployableContainer(); |
| 106 | + List<DeploymentDescription> deployments = activeDeployments.remove(testClass.getJavaClass()); |
| 107 | + if (deployments == null) { |
| 108 | + throw new IllegalStateException("After undeploy on test class that wasn't deployed?"); |
| 109 | + } |
| 110 | + for (DeploymentDescription deployable : deployments) { |
| 111 | + if (deployable.isDescriptorDeployment()) { |
| 112 | + container.undeploy(deployable.getDescriptor()); |
| 113 | + } |
| 114 | + else { |
| 115 | + container.undeploy(deployable.getArchive()); |
| 116 | + } |
| 117 | + } |
105 | 118 |
|
106 |
| - List<DeploymentDescription> deployments = activeDeployments.remove(testClass.getJavaClass()); |
107 |
| - if (deployments == null) { |
108 |
| - throw new IllegalStateException("After undeploy on test class that wasn't deployed?"); |
109 |
| - } |
110 |
| - for (DeploymentDescription deployable: deployments) { |
111 |
| - if (deployable.isDescriptorDeployment()) { |
112 |
| - container.undeploy(deployable.getDescriptor()); |
113 |
| - } |
114 |
| - else { |
115 |
| - container.undeploy(deployable.getArchive()); |
116 |
| - } |
| 119 | + tckContainer.teardownTopics(topicNames); |
117 | 120 | }
|
118 | 121 |
|
119 |
| - tckContainer.teardownTopics(topicNames); |
120 |
| - } |
121 |
| - |
122 |
| - private String[] getTopicsUsedByTestClass(TestClass testClass) { |
123 |
| - Topics topics = testClass.getAnnotation(Topics.class); |
124 |
| - String[] topicNames; |
125 |
| - if (topics != null) { |
126 |
| - topicNames = topics.value(); |
127 |
| - } |
128 |
| - else { |
129 |
| - topicNames = new String[0]; |
| 122 | + private String[] getTopicsUsedByTestClass(TestClass testClass) { |
| 123 | + Topics topics = testClass.getAnnotation(Topics.class); |
| 124 | + String[] topicNames; |
| 125 | + if (topics != null) { |
| 126 | + topicNames = topics.value(); |
| 127 | + } |
| 128 | + else { |
| 129 | + topicNames = new String[0]; |
| 130 | + } |
| 131 | + return topicNames; |
130 | 132 | }
|
131 |
| - return topicNames; |
132 |
| - } |
133 | 133 |
|
134 | 134 | }
|
0 commit comments