Skip to content

Commit 1ada490

Browse files
committed
add testing changes
1 parent 32e128a commit 1ada490

File tree

12 files changed

+791
-98
lines changed

12 files changed

+791
-98
lines changed

sdk/clientcore/annotation-processor-test/pom.xml

Lines changed: 77 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,8 @@
4646
--add-exports io.clientcore.core/io.clientcore.core.implementation.http=ALL-UNNAMED
4747
--add-exports io.clientcore.core/io.clientcore.core.implementation.http.serializer=ALL-UNNAMED
4848
--add-exports io.clientcore.core/io.clientcore.core.implementation.utils=ALL-UNNAMED
49-
5049
--add-exports io.clientcore.annotation.processor.test/io.clientcore.annotation.processor.test.shared=ALL-UNNAMED
51-
--add-opens io.clientcore.annotation.processor.test/io.clientcore.annotation.processor.test.shared.=ALL-UNNAMED
50+
--add-opens io.clientcore.annotation.processor.test/io.clientcore.annotation.processor.test.shared=ALL-UNNAMED
5251
</javaModulesSurefireArgLine>
5352
</properties>
5453

@@ -60,13 +59,6 @@
6059
</dependency>
6160

6261
<!-- Test dependencies -->
63-
<dependency>
64-
<groupId>io.clientcore</groupId>
65-
<artifactId>core</artifactId>
66-
<version>1.0.0-beta.8</version> <!-- {x-version-update;unreleased_io.clientcore:core;dependency} -->
67-
<type>test-jar</type>
68-
<scope>test</scope>
69-
</dependency>
7062
<dependency>
7163
<groupId>org.eclipse.jetty</groupId>
7264
<artifactId>jetty-server</artifactId>
@@ -148,6 +140,34 @@
148140
</excludes>
149141
</configuration>
150142
</execution>
143+
144+
<execution>
145+
<id>run-annotation-processing-test</id>
146+
<phase>generate-test-sources</phase>
147+
<goals>
148+
<goal>testCompile</goal>
149+
</goals>
150+
<configuration>
151+
<source>1.8</source>
152+
<target>1.8</target>
153+
<release>8</release>
154+
<proc>only</proc>
155+
<generatedTestSourcesDirectory>${project.build.directory}/generated-test-sources/</generatedTestSourcesDirectory>
156+
<annotationProcessorPaths>
157+
<annotationProcessorPath>
158+
<groupId>io.clientcore</groupId>
159+
<artifactId>annotation-processor</artifactId>
160+
<version>1.0.0-beta.2</version> <!-- {x-version-update;unreleased_io.clientcore:annotation-processor;dependency} -->
161+
</annotationProcessorPath>
162+
</annotationProcessorPaths>
163+
<annotationProcessors>
164+
<annotationProcessor>io.clientcore.annotation.processor.AnnotationProcessor</annotationProcessor>
165+
</annotationProcessors>
166+
<compilerArgs>
167+
<arg>-Xlint:-options</arg>
168+
</compilerArgs>
169+
</configuration>
170+
</execution>
151171
</executions>
152172

153173
<dependencies>
@@ -176,8 +196,56 @@
176196
</sources>
177197
</configuration>
178198
</execution>
199+
200+
<execution>
201+
<id>add-generated-test-sources</id>
202+
<phase>generate-test-sources</phase>
203+
<goals>
204+
<goal>add-test-source</goal>
205+
</goals>
206+
<configuration>
207+
<sources>
208+
<source>${basedir}/target/generated-test-sources</source>
209+
</sources>
210+
</configuration>
211+
</execution>
212+
</executions>
213+
</plugin>
214+
215+
<plugin>
216+
<groupId>org.apache.maven.plugins</groupId>
217+
<artifactId>maven-failsafe-plugin</artifactId>
218+
<version>3.5.2</version> <!-- {x-version-update;org.apache.maven.plugins:maven-failsafe-plugin;external_dependency} -->
219+
</plugin>
220+
221+
<!-- HttpClientTests is inherited by tests in http-okhttp3 -->
222+
<plugin>
223+
<groupId>org.apache.maven.plugins</groupId>
224+
<artifactId>maven-jar-plugin</artifactId>
225+
<version>3.4.2</version> <!-- {x-version-update;org.apache.maven.plugins:maven-jar-plugin;external_dependency} -->
226+
<executions>
227+
<execution>
228+
<id>test-jar</id>
229+
<phase>test-compile</phase>
230+
<goals>
231+
<goal>test-jar</goal>
232+
</goals>
233+
</execution>
234+
235+
<execution>
236+
<id>default-jar</id>
237+
<phase>package</phase>
238+
<configuration>
239+
<archive>
240+
<manifestEntries>
241+
<Multi-Release>true</Multi-Release>
242+
</manifestEntries>
243+
</archive>
244+
</configuration>
245+
</execution>
179246
</executions>
180247
</plugin>
181248
</plugins>
182249
</build>
250+
183251
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package io.clientcore.annotation.processor.test.implementation.models;

sdk/clientcore/annotation-processor-test/src/main/java/module-info.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
module annotation.processor.test {
22
requires transitive io.clientcore.core;
3+
requires jdk.httpserver;
34

45
// TODO: refactor Foo class to implement JsonSerializable
56
exports io.clientcore.annotation.processor.test.implementation.models to io.clientcore.core;

sdk/clientcore/annotation-processor-test/src/test/java/io/clientcore/annotation/processor/test/http/models/FooListResult.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
package io.clientcore.annotation.processor.test.http.models;
55

6-
import io.clientcore.core.implementation.serializer.Foo;
6+
import io.clientcore.annotation.processor.test.implementation.models.Foo;
77
import io.clientcore.core.serialization.json.JsonReader;
88
import io.clientcore.core.serialization.json.JsonSerializable;
99
import io.clientcore.core.serialization.json.JsonToken;

sdk/clientcore/annotation-processor-test/src/test/java/io/clientcore/annotation/processor/test/implementation/client/JdkHttpClientIT.java

Lines changed: 57 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,32 +18,32 @@
1818
import io.clientcore.core.implementation.http.client.JdkHttpClient;
1919
import io.clientcore.core.models.binarydata.BinaryData;
2020
import io.clientcore.core.utils.Context;
21-
import io.clientcore.core.utils.TestUtils;
22-
import org.conscrypt.Conscrypt;
23-
import org.junit.jupiter.api.AfterAll;
24-
import org.junit.jupiter.api.BeforeAll;
25-
import org.junit.jupiter.api.Test;
26-
import org.junit.jupiter.api.condition.DisabledForJreRange;
27-
import org.junit.jupiter.api.condition.JRE;
28-
import org.junit.jupiter.api.parallel.Execution;
29-
import org.junit.jupiter.api.parallel.ExecutionMode;
30-
31-
import javax.net.ssl.SSLContext;
32-
import javax.net.ssl.TrustManager;
33-
import javax.servlet.ServletException;
3421
import java.io.IOException;
3522
import java.net.URI;
23+
import java.nio.ByteBuffer;
3624
import java.nio.charset.StandardCharsets;
3725
import java.security.GeneralSecurityException;
3826
import java.util.ArrayList;
3927
import java.util.Arrays;
4028
import java.util.Collections;
4129
import java.util.List;
30+
import java.util.Objects;
4231
import java.util.concurrent.Callable;
4332
import java.util.concurrent.ForkJoinPool;
4433
import java.util.concurrent.TimeUnit;
34+
import javax.net.ssl.SSLContext;
35+
import javax.net.ssl.TrustManager;
36+
import javax.servlet.ServletException;
37+
import org.conscrypt.Conscrypt;
38+
import org.junit.jupiter.api.AfterAll;
39+
import org.junit.jupiter.api.BeforeAll;
40+
import org.junit.jupiter.api.Test;
41+
import org.junit.jupiter.api.condition.DisabledForJreRange;
42+
import org.junit.jupiter.api.condition.JRE;
43+
import org.junit.jupiter.api.parallel.Execution;
44+
import org.junit.jupiter.api.parallel.ExecutionMode;
4545

46-
import static io.clientcore.core.utils.TestUtils.assertArraysEqual;
46+
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
4747
import static org.junit.jupiter.api.Assertions.assertEquals;
4848
import static org.junit.jupiter.api.Assertions.assertTrue;
4949

@@ -264,7 +264,7 @@ public void testCustomSslSocketFactory() throws IOException, GeneralSecurityExce
264264

265265
try (Response<BinaryData> response
266266
= httpClient.send(new HttpRequest().setMethod(HttpMethod.GET).setUri(httpsUri(server, "/short")))) {
267-
TestUtils.assertArraysEqual(SHORT_BODY, response.getValue().toBytes());
267+
assertArraysEqual(SHORT_BODY, response.getValue().toBytes());
268268
}
269269
}
270270

@@ -301,4 +301,46 @@ private static Response<BinaryData> doRequest(HttpClient client, String path) th
301301

302302
return client.send(request);
303303
}
304+
305+
/**
306+
* Asserts that two arrays are equal in an optimized way when they are equal (common case).
307+
*
308+
* @param expected Expected array.
309+
* @param actual Actual array.
310+
*/
311+
public static void assertArraysEqual(byte[] expected, byte[] actual) {
312+
assertArraysEqual(expected, 0, expected.length, actual, actual.length);
313+
}
314+
315+
/**
316+
* Asserts that two arrays are equal in an optimized way when they are equal (common case).
317+
*
318+
* @param expected Expected array.
319+
* @param expectedOffset Offset to begin comparing in the expected array.
320+
* @param expectedLength Amount of bytes to compare in the expected array.
321+
* @param actual Actual array.
322+
*/
323+
public static void assertArraysEqual(byte[] expected, int expectedOffset, int expectedLength, byte[] actual) {
324+
assertArraysEqual(expected, expectedOffset, expectedLength, actual, actual.length);
325+
}
326+
327+
/**
328+
* Asserts that two arrays are equal in an optimized way when they are equal (common case).
329+
*
330+
* @param expected Expected array.
331+
* @param expectedOffset Offset to begin comparing in the expected array.
332+
* @param expectedLength Amount of bytes to compare in the expected array.
333+
* @param actual Actual array.
334+
* @param actualLength Amount of bytes to compare in the actual array.
335+
*/
336+
private static void assertArraysEqual(byte[] expected, int expectedOffset, int expectedLength, byte[] actual,
337+
int actualLength) {
338+
339+
if (!Objects.equals(ByteBuffer.wrap(expected, expectedOffset, expectedLength),
340+
ByteBuffer.wrap(actual, 0, actualLength))) {
341+
342+
assertArrayEquals(Arrays.copyOfRange(expected, expectedOffset, expectedOffset + expectedLength),
343+
Arrays.copyOfRange(actual, 0, actualLength));
344+
}
345+
}
304346
}

0 commit comments

Comments
 (0)