Skip to content

Commit

Permalink
Add docs and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lmolkova committed Aug 18, 2021
1 parent 9fe076e commit c774a0f
Show file tree
Hide file tree
Showing 9 changed files with 208 additions and 27 deletions.
126 changes: 108 additions & 18 deletions sdk/core/azure-core-jackson-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-core</artifactId>
<version>1.19.0-beta.2</version> <!-- {x-version-update;com.azure:azure-core;current} -->
<version>1.20.0-beta.1</version> <!-- {x-version-update;com.azure:azure-core;current} -->
</dependency>

<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-core</artifactId>
<version>1.19.0-beta.2</version> <!-- {x-version-update;com.azure:azure-core;current} -->
<version>1.20.0-beta.1</version> <!-- {x-version-update;com.azure:azure-core;current} -->
<classifier>tests</classifier>
<type>test-jar</type>
<scope>test</scope>
Expand Down Expand Up @@ -163,36 +163,49 @@
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M3</version> <!-- {x-version-update;org.apache.maven.plugins:maven-surefire-plugin;external_dependency} -->
<configuration>
<dependenciesToScan>
<dependency>com.azure:azure-core</dependency>
</dependenciesToScan>
<excludes>
<!-- TODO(limolkova) requires azure-core test resources-->
<exclude>**/RestProxyXMLTests.java</exclude>
</excludes>
</configuration>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.2</version> <!-- {x-version-update;org.apache.maven.plugins:maven-jar-plugin;external_dependency} -->
<executions>
<execution>
<id>test-jar</id>
<phase>test-compile</phase>
<goals>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

<profiles>
<profile>
<id>java-lts</id>
<id>default</id>
<activation>
<jdk>[11,)</jdk>
<activeByDefault>true</activeByDefault>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M3</version> <!-- {x-version-update;org.apache.maven.plugins:maven-surefire-plugin;external_dependency} -->
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
</plugins>
</build>

</profile>

<profile>
<id>jackson-version-test-matrix</id>
<id>jackson-supported-version-test-matrix</id>
<activation>
<property><name>env.AZURE_CORE_TEST_JACKSON_VERSION</name></property>
<property><name>env.AZURE_CORE_TEST_SUPPORTED_JACKSON_VERSION</name></property>
</activation>
<properties>
<jackson.version>${env.AZURE_CORE_TEST_JACKSON_VERSION}</jackson.version>
<jackson.version>${env.AZURE_CORE_TEST_SUPPORTED_JACKSON_VERSION}</jackson.version>
</properties>
<dependencies>
<!--Have to redeclare dependencies here to allow x-version-update script to work properly-->
Expand Down Expand Up @@ -226,8 +239,85 @@
<version>${jackson.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M3</version> <!-- {x-version-update;org.apache.maven.plugins:maven-surefire-plugin;external_dependency} -->
<configuration>
<dependenciesToScan>
<dependency>com.azure:azure-core</dependency>
</dependenciesToScan>
<excludes>
<!-- TODO(limolkova) requires azure-core test resources-->
<exclude>**/RestProxyXMLTests.java</exclude>
<exclude>**/UnsupportedJacksonVersionsTests.java</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</profile>

<profile>
<id>jackson-unsupported-version-test</id>
<activation>
<property><name>env.AZURE_CORE_TEST_UNSUPPORTED_JACKSON_VERSION</name></property>
</activation>
<properties>
<jackson.version>${env.AZURE_CORE_TEST_UNSUPPORTED_JACKSON_VERSION}</jackson.version>
</properties>
<dependencies>
<!--Have to redeclare dependencies here to allow x-version-update script to work properly-->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>${jackson.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>${jackson.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
<version>${jackson.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-xml</artifactId>
<version>${jackson.version}</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M3</version> <!-- {x-version-update;org.apache.maven.plugins:maven-surefire-plugin;external_dependency} -->
<configuration>
<includes>
<include>**/UnsupportedJacksonVersionsTests.java</include>
</includes>
</configuration>
</plugin>
</plugins>
</build>

</profile>
</profiles>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.azure.core.implementation.jackson;

import com.azure.core.util.CoreUtils;
import com.azure.core.util.serializer.JacksonAdapter;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.assertThrows;

public class UnsupportedJacksonVersionsTests {
@Test
public void testme() {
String jacksonVersionString = ObjectMapper.class.getPackage().getImplementationVersion();
String azureCoreVersion = CoreUtils
.getProperties("azure-core.properties")
.getOrDefault("version", null);

JacksonVersion version = JacksonVersion.getInstance();
String helpInfo = version.getHelpInfo();
assertTrue(helpInfo.contains("jackson-annotations=" + jacksonVersionString));
assertTrue(helpInfo.contains("jackson-core=" + jacksonVersionString));
assertTrue(helpInfo.contains("jackson-databind=" + jacksonVersionString));
assertTrue(helpInfo.contains("jackson-dataformat-xml=" + jacksonVersionString));
assertTrue(helpInfo.contains("jackson-datatype-jsr310=" + jacksonVersionString));
assertTrue(helpInfo.contains("azure-core=" + azureCoreVersion));

Error error = assertThrows(Error.class, () -> new JacksonAdapter());
assertTrue(error.getMessage().contains(helpInfo));
}
}
2 changes: 1 addition & 1 deletion sdk/core/azure-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,8 @@
--add-opens com.azure.core/com.azure.core.implementation.http=ALL-UNNAMED
--add-opens com.azure.core/com.azure.core.implementation.models.jsonflatten=com.fasterxml.jackson.databind
--add-opens com.azure.core/com.azure.core.implementation.models.jsonflatten=ALL-UNNAMED
--add-opens com.azure.core/com.azure.core.implementation.jackson=ALL-UNNAMED
--add-opens com.azure.core/com.azure.core.implementation.serializer=ALL-UNNAMED
--add-opens com.azure.core/com.azure.core.implementation.jackson=ALL-UNNAMED
--add-opens com.azure.core/com.azure.core.models=ALL-UNNAMED
--add-opens com.azure.core/com.azure.core.util=ALL-UNNAMED
--add-opens com.azure.core/com.azure.core.util.logging=ALL-UNNAMED
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import com.azure.core.util.logging.ClientLogger;

/**
* Provides information about Jackson package versions used and detects potential issues.
* Provides information about Jackson package versions used, detects and logs errors.
*/
final class JacksonVersion {
private SemanticVersion annotationsVersion;
Expand Down Expand Up @@ -51,10 +51,18 @@ private JacksonVersion() {
logger.info(helpString);
}

/**
* Returns help info containing actual detected package versions.
*
* @return diagnostics information with detected versions.
*/
public String getHelpInfo() {
return helpString;
}

/**
* Gets {@code SemanticVersion} for given class name
*/
private SemanticVersion getVersion(String className) {
try {
return SemanticVersion.getPackageVersionForClass(className);
Expand All @@ -65,6 +73,10 @@ private SemanticVersion getVersion(String className) {
}

private static JacksonVersion instance = null;

/**
* Gets {@code JacksonVersion} instance singleton.
*/
public static synchronized JacksonVersion getInstance() {
if (instance == null) {
instance = new JacksonVersion();
Expand All @@ -73,6 +85,9 @@ public static synchronized JacksonVersion getInstance() {
return instance;
}

/**
* Checks package version and logs if any issues detected.
*/
private void checkVersion(SemanticVersion version, String packageName) {
if (!version.isValid()) {
logger.warning("Could not find version of '{}'.", packageName);
Expand All @@ -90,6 +105,9 @@ private void checkVersion(SemanticVersion version, String packageName) {
}
}

/**
* Generates help information with versions detected in runtime.
*/
private String formatHelpString() {
// TODO(limolkova): add link to troubleshooting docs
return new StringBuilder()
Expand Down
2 changes: 1 addition & 1 deletion sdk/core/azure-core/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@
opens com.azure.core.util.serializer to com.fasterxml.jackson.databind;
opens com.azure.core.implementation to com.fasterxml.jackson.databind;
opens com.azure.core.implementation.logging to com.fasterxml.jackson.databind;
opens com.azure.core.implementation.jackson to com.fasterxml.jackson.databind;
opens com.azure.core.implementation.serializer to com.fasterxml.jackson.databind;
opens com.azure.core.implementation.jackson to com.fasterxml.jackson.databind;
opens com.azure.core.http.rest to com.fasterxml.jackson.databind;

// Service Provider Interfaces
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,17 @@ public void malformedVersion(String versionStr) {

@Test
public void classVersion() {
// TODO (limolkova) for some reason (investigating) package versions are available only for junit
// in tests in azure-core project, it does not affect
SemanticVersion version = SemanticVersion.getPackageVersionForClass("com.fasterxml.jackson.databind.ObjectMapper"); // org.junit.jupiter.api.Test");
// TODO (limolkova) for some reason (investigating) package versions are not available
// in tests for azure-core project, it does not affect real applications

SemanticVersion version = SemanticVersion.getPackageVersionForClass("org.junit.jupiter.api.Test");
assertTrue(version.isValid());
}

@ParameterizedTest
@ValueSource(strings = {"nonsense", ""})
public void malformedClassVersion(String className) {
SemanticVersion malformed = SemanticVersion.getPackageVersionForClass(className);
assertFalse(malformed.isValid());
}
}
File renamed without changes.
21 changes: 18 additions & 3 deletions sdk/core/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,30 @@ stages:
- template: /eng/pipelines/templates/stages/archetype-sdk-tests.yml
parameters:
ServiceDirectory: core
TestName: 'jackson_versions'
TestName: 'jackson_supported_versions'
MatrixConfigs:
- Name: jackson_version_tests
Path: sdk/core/version-matrix.json
Path: sdk/core/supported-version-matrix.json
Selection: sparse
NonSparseParameters:
- AZURE_CORE_TEST_JACKSON_VERSION
- AZURE_CORE_TEST_SUPPORTED_JACKSON_VERSION
GenerateVMJobs: true
Artifacts:
- name: azure-core-jackson-tests
groupId: com.azure
safeName: azurecorejacksontests
- template: /eng/pipelines/templates/stages/archetype-sdk-tests.yml
parameters:
ServiceDirectory: core
TestName: 'jackson_unsupported_versions'
MatrixConfigs:
- Name: jackson_version_tests
Path: sdk/core/unsupported-version-matrix.json
Selection: sparse
NonSparseParameters:
- AZURE_CORE_TEST_UNSUPPORTED_JACKSON_VERSION
GenerateVMJobs: true
Artifacts:
- name: azure-core-jackson-tests
groupId: com.azure
safeName: azurecorejacksontests
17 changes: 17 additions & 0 deletions sdk/core/unsupported-version-matrix.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"displayNames": {
"2.9.10": "jackson2_9",
},
"matrix": {
"Agent": {
"ubuntu-20.04": { "OSVmImage": "MMSUbuntu20.04", "Pool": "azsdk-pool-mms-ubuntu-2004-general" }
},
"JavaTestVersion": "1.11",
"AZURE_TEST_HTTP_CLIENTS": "netty",
"TestGoals": "surefire:test",
"AZURE_CORE_TEST_JACKSON_VERSION": [
"2.9.10",
],
"TestFromSource": true
}
}

0 comments on commit c774a0f

Please sign in to comment.