@@ -32,15 +32,23 @@ class MigrateEjbDeploymentDescriptorTest {
32
32
public static final String EJB_CLASS_FQNAME = "com.example.jee.ejb.stateless.local.deploymentdescriptor.NoInterfaceViewBean" ;
33
33
public static final String EJB_TYPE = "Stateless" ;
34
34
private static final String EJB_NAME = "noInterfaceView" ;
35
+ private static final String EJB_WITH_MAPPED_NAME = "MappedNameView" ;
36
+ private static final String EJB_WITH_MAPPED_CLASS_FQNAME = "com.example.jee.ejb.stateless.local.deploymentdescriptor.MappedNameView" ;
37
+ private static final String MAPPED_NAME = "java:comp/env/ejb/MappedNameViewBean" ;
38
+ private static final String EJB_WITH_REMOTE_INTERFACE_NAME = "RemoteInterfaceView" ;
39
+ public static final String EJB_WITH_REMOTE_INTERFACE_FQDN = "com.example.jee.ejb.stateless.local.deploymentdescriptor.RemoteInterfaceView" ;
40
+ private static final String REMOTE_EJB_INTERFACE = "com.example.jee.ejb.stateless.local.deploymentdescriptor.RemoteInterface" ;
41
+ private static final String EJB_WITH_LOCAL_INTERFACE_NAME = "LocalInterfaceView" ;
42
+ public static final String EJB_WITH_LOCAL_INTERFACE_FQDN = "com.example.jee.ejb.stateless.local.deploymentdescriptor.LocalInterfaceView" ;
43
+ private static final String LOCAL_EJB_INTERFACE = "com.example.jee.ejb.stateless.local.deploymentdescriptor.LocalInterface" ;
35
44
36
45
@ Test
37
46
void givenDeploymentDescriptorContainsEjbWhenMatchingClassIsFoundThenStatelessAnnotationShouldBeOverwritten () {
38
47
// setup fixture
39
- String javaSource =
40
- "package com.example.jee.ejb.stateless.local.deploymentdescriptor;\n " +
41
- "import javax.ejb.Stateless;\n " +
42
- "@Stateless(name=\" banana\" )\n " +
43
- "public class NoInterfaceViewBean {}" ;
48
+ String javaSource = "package com.example.jee.ejb.stateless.local.deploymentdescriptor;\n " +
49
+ "import javax.ejb.Stateless;\n " +
50
+ "@Stateless(name=\" banana\" )\n " +
51
+ "public class NoInterfaceViewBean {}" ;
44
52
45
53
String expected = "package com.example.jee.ejb.stateless.local.deploymentdescriptor;\n " +
46
54
"\n " +
@@ -71,6 +79,156 @@ void givenDeploymentDescriptorContainsEjbWhenMatchingClassIsFoundThenStatelessAn
71
79
.build ();
72
80
73
81
82
+ // call SUT
83
+ MigrateEjbDeploymentDescriptor sut = new MigrateEjbDeploymentDescriptor ();
84
+ sut .apply (projectContext );
85
+
86
+ // verify...
87
+ assertThat (projectContext .getProjectJavaSources ().list ().size ()).isEqualTo (1 );
88
+ assertThat (projectContext .getProjectJavaSources ().list ().get (0 ).print ()).isEqualTo (expected );
89
+ List <EjbJarXml > deploymentDescriptors = projectContext .search (new GenericTypeListFilter <>(EjbJarXml .class ));
90
+ assertThat (deploymentDescriptors ).isEmpty ();
91
+ }
92
+
93
+ @ Test
94
+ void givenDeploymentDescriptorContainsEjbWithMappedName_whenMatchingClassIsFound_thenStatelessAnnotationShouldBeOverwritten () {
95
+ // setup fixture
96
+ String javaSource =
97
+ "package com.example.jee.ejb.stateless.local.deploymentdescriptor;\n " +
98
+ "import javax.ejb.Stateless;\n " +
99
+ "@Stateless(name=\" banana\" )\n " +
100
+ "public class MappedNameView {}" ;
101
+
102
+ String expected = "package com.example.jee.ejb.stateless.local.deploymentdescriptor;\n " +
103
+ "\n " +
104
+ "import javax.ejb.Stateless;\n " +
105
+ "\n " +
106
+ "@Stateless(name = \" " + EJB_WITH_MAPPED_NAME + "\" , mappedName = \" " + MAPPED_NAME + "\" )\n " +
107
+ "public class MappedNameView {}" ;
108
+
109
+ String deploymentDescriptorXml = "<ejb-jar xmlns=\" http://xmlns.jcp.org/xml/ns/javaee\" \n " +
110
+ " xmlns:xsi=\" http://www.w3.org/2001/XMLSchema-instance\" \n " +
111
+ " xsi:schemaLocation=\" http://xmlns.jcp.org/xml/ns/javaee\n " +
112
+ " http://xmlns.jcp.org/xml/ns/javaee/ejb-jar_3_2.xsd\" \n " +
113
+ " version=\" 3.2\" >\n " +
114
+ " <enterprise-beans>\n " +
115
+ " <session>\n " +
116
+ " <ejb-name>" + EJB_WITH_MAPPED_NAME + "</ejb-name>\n " +
117
+ " <ejb-class>" + EJB_WITH_MAPPED_CLASS_FQNAME + "</ejb-class>\n " +
118
+ " <mapped-name>" + MAPPED_NAME + "</mapped-name>\n " +
119
+ " <session-type>" + EJB_TYPE + "</session-type>\n " +
120
+ " </session>\n " +
121
+ " </enterprise-beans>\n " +
122
+ "</ejb-jar>" ;
123
+
124
+ ProjectContext projectContext = TestProjectContext .buildProjectContext ()
125
+ .addProjectResource (Path .of ("./src/main/resources/META-INF/ejb-jar.xml" ), deploymentDescriptorXml )
126
+ .withJavaSources (javaSource )
127
+ .withBuildFileHavingDependencies ("javax.ejb:javax.ejb-api:3.2" )
128
+ .addRegistrar (new JeeEjbJarXmlProjectResourceRegistrar ())
129
+ .build ();
130
+
131
+
132
+ // call SUT
133
+ MigrateEjbDeploymentDescriptor sut = new MigrateEjbDeploymentDescriptor ();
134
+ sut .apply (projectContext );
135
+
136
+ // verify...
137
+ assertThat (projectContext .getProjectJavaSources ().list ().size ()).isEqualTo (1 );
138
+ assertThat (projectContext .getProjectJavaSources ().list ().get (0 ).print ()).isEqualTo (expected );
139
+ List <EjbJarXml > deploymentDescriptors = projectContext .search (new GenericTypeListFilter <>(EjbJarXml .class ));
140
+ assertThat (deploymentDescriptors ).isEmpty ();
141
+ }
142
+
143
+ @ Test
144
+ void givenDeploymentDescriptorContainsEjbWithRemoteInterface_whenMatchingClassIsFound_thenStatelessRemoteAnnotationShouldBeGenerated () {
145
+ // setup fixture
146
+ String javaSource =
147
+ "package com.example.jee.ejb.stateless.local.deploymentdescriptor;\n " +
148
+ "import javax.ejb.Stateless;\n " +
149
+ "public class RemoteInterfaceView implements RemoteInterface{}" ;
150
+
151
+ String expected = "package com.example.jee.ejb.stateless.local.deploymentdescriptor;\n " +
152
+ "import javax.ejb.Remote;\n " +
153
+ "import javax.ejb.Stateless;\n " +
154
+ "\n " +
155
+ "@Stateless(name = \" " + EJB_WITH_REMOTE_INTERFACE_NAME + "\" )\n " +
156
+ "@Remote(" + REMOTE_EJB_INTERFACE + ".class)\n " +
157
+ "public class RemoteInterfaceView implements RemoteInterface {}" ;
158
+
159
+ String deploymentDescriptorXml = "<ejb-jar xmlns=\" http://xmlns.jcp.org/xml/ns/javaee\" \n " +
160
+ " xmlns:xsi=\" http://www.w3.org/2001/XMLSchema-instance\" \n " +
161
+ " xsi:schemaLocation=\" http://xmlns.jcp.org/xml/ns/javaee\n " +
162
+ " http://xmlns.jcp.org/xml/ns/javaee/ejb-jar_3_2.xsd\" \n " +
163
+ " version=\" 3.2\" >\n " +
164
+ " <enterprise-beans>\n " +
165
+ " <session>\n " +
166
+ " <ejb-name>" + EJB_WITH_REMOTE_INTERFACE_NAME + "</ejb-name>\n " +
167
+ " <ejb-class>" + EJB_WITH_REMOTE_INTERFACE_FQDN + "</ejb-class>\n " +
168
+ " <remote>" + REMOTE_EJB_INTERFACE + "</remote>\n " +
169
+ " <session-type>" + EJB_TYPE + "</session-type>\n " +
170
+ " </session>\n " +
171
+ " </enterprise-beans>\n " +
172
+ "</ejb-jar>" ;
173
+
174
+ ProjectContext projectContext = TestProjectContext .buildProjectContext ()
175
+ .addProjectResource (Path .of ("./src/main/resources/META-INF/ejb-jar.xml" ), deploymentDescriptorXml )
176
+ .withJavaSources (javaSource )
177
+ .withBuildFileHavingDependencies ("javax.ejb:javax.ejb-api:3.2" )
178
+ .addRegistrar (new JeeEjbJarXmlProjectResourceRegistrar ())
179
+ .build ();
180
+
181
+
182
+ // call SUT
183
+ MigrateEjbDeploymentDescriptor sut = new MigrateEjbDeploymentDescriptor ();
184
+ sut .apply (projectContext );
185
+
186
+ // verify...
187
+ assertThat (projectContext .getProjectJavaSources ().list ().size ()).isEqualTo (1 );
188
+ assertThat (projectContext .getProjectJavaSources ().list ().get (0 ).print ()).isEqualTo (expected );
189
+ List <EjbJarXml > deploymentDescriptors = projectContext .search (new GenericTypeListFilter <>(EjbJarXml .class ));
190
+ assertThat (deploymentDescriptors ).isEmpty ();
191
+ }
192
+
193
+ @ Test
194
+ void givenDeploymentDescriptorContainsEjbWithLocalInterface_whenMatchingClassIsFound_thenStatelessLocalAnnotationShouldBeGenerated () {
195
+ // setup fixture
196
+ String javaSource =
197
+ "package com.example.jee.ejb.stateless.local.deploymentdescriptor;\n " +
198
+ "import javax.ejb.Stateless;\n " +
199
+ "public class LocalInterfaceView implements LocalInterface{}" ;
200
+
201
+ String expected = "package com.example.jee.ejb.stateless.local.deploymentdescriptor;\n " +
202
+ "import javax.ejb.Local;\n " +
203
+ "import javax.ejb.Stateless;\n " +
204
+ "\n " +
205
+ "@Stateless(name = \" " + EJB_WITH_LOCAL_INTERFACE_NAME + "\" )\n " +
206
+ "@Local(" + LOCAL_EJB_INTERFACE + ".class)\n " +
207
+ "public class LocalInterfaceView implements LocalInterface {}" ;
208
+
209
+ String deploymentDescriptorXml = "<ejb-jar xmlns=\" http://xmlns.jcp.org/xml/ns/javaee\" \n " +
210
+ " xmlns:xsi=\" http://www.w3.org/2001/XMLSchema-instance\" \n " +
211
+ " xsi:schemaLocation=\" http://xmlns.jcp.org/xml/ns/javaee\n " +
212
+ " http://xmlns.jcp.org/xml/ns/javaee/ejb-jar_3_2.xsd\" \n " +
213
+ " version=\" 3.2\" >\n " +
214
+ " <enterprise-beans>\n " +
215
+ " <session>\n " +
216
+ " <ejb-name>" + EJB_WITH_LOCAL_INTERFACE_NAME + "</ejb-name>\n " +
217
+ " <ejb-class>" + EJB_WITH_LOCAL_INTERFACE_FQDN + "</ejb-class>\n " +
218
+ " <local>" + LOCAL_EJB_INTERFACE + "</local>\n " +
219
+ " <session-type>" + EJB_TYPE + "</session-type>\n " +
220
+ " </session>\n " +
221
+ " </enterprise-beans>\n " +
222
+ "</ejb-jar>" ;
223
+
224
+ ProjectContext projectContext = TestProjectContext .buildProjectContext ()
225
+ .addProjectResource (Path .of ("./src/main/resources/META-INF/ejb-jar.xml" ), deploymentDescriptorXml )
226
+ .withJavaSources (javaSource )
227
+ .withBuildFileHavingDependencies ("javax.ejb:javax.ejb-api:3.2" )
228
+ .addRegistrar (new JeeEjbJarXmlProjectResourceRegistrar ())
229
+ .build ();
230
+
231
+
74
232
// call SUT
75
233
MigrateEjbDeploymentDescriptor sut = new MigrateEjbDeploymentDescriptor ();
76
234
sut .apply (projectContext );
0 commit comments