Skip to content
Snippets Groups Projects
Commit 57886068 authored by Rustam Lotsmanenko (EPAM)'s avatar Rustam Lotsmanenko (EPAM)
Browse files

Enable unit tests.

parent 0f6db198
No related branches found
No related tags found
1 merge request!382Enable unit tests.
......@@ -49,7 +49,7 @@ include:
- local: "devops/gc/pipeline/override-stages.yml"
.maven:
image: maven:3.8.3-openjdk-17-slim
image: maven:3.9.3-eclipse-temurin-17
tags: ['osdu-medium']
variables:
MAVEN_REPO_PATH: "$CI_PROJECT_DIR/.m2/repository"
......
......@@ -152,9 +152,16 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
<version>3.0.0-M9</version>
<dependencies>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit47</artifactId>
<version>3.0.0-M9</version>
</dependency>
</dependencies>
<configuration>
<argLine>@{argLine} --add-opens java.base/java.lang=ALL_UNNAMED</argLine>
<trimStackTrace>false</trimStackTrace>
</configuration>
</plugin>
</plugins>
......
......@@ -211,9 +211,16 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
<version>3.0.0-M9</version>
<dependencies>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit47</artifactId>
<version>3.0.0-M9</version>
</dependency>
</dependencies>
<configuration>
<argLine>@{argLine} --add-opens java.base/java.lang=ALL_UNNAMED</argLine>
<trimStackTrace>false</trimStackTrace>
</configuration>
</plugin>
<plugin>
......
......@@ -19,7 +19,6 @@ package org.opengroup.osdu.register.action.services;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.opengroup.osdu.register.action.model.ParsedAction;
import org.opengroup.osdu.core.common.model.http.AppException;
import org.opengroup.osdu.core.common.logging.JaxRsDpsLog;
import org.junit.Test;
import org.junit.runner.RunWith;
......@@ -235,12 +234,13 @@ public class ParseJsonIntoActionTest {
assertEquals(expectedError, response.getErrors());
}
@Test(expected = AppException.class)
@Test
public void should_throwAppException_given_RegexBackTracking() {
String url = "https://myapp.osdu.opengroup.org/action/{data.timeout:(x+x+)+y}";
JsonNode testPayload = createTestPayload();
this.sut.parse(url, testPayload);
ParsedAction parse = this.sut.parse(url, testPayload);
assertEquals("Regex: (x+x+)+y failed to extract a value from the test payload.", parse.getErrors());
}
private JsonNode createTestPayload() {
......
......@@ -17,9 +17,11 @@
package org.opengroup.osdu.register.utils;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.io.Resources;
import com.reprezen.kaizen.oasparser.OpenApiParser;
import com.reprezen.kaizen.oasparser.model3.OpenApi3;
import java.io.FileReader;
import java.net.URI;
import java.net.URISyntaxException;
import org.opengroup.osdu.register.ddms.model.Ddms;
import org.opengroup.osdu.register.ddms.model.RegisteredInterface;
......@@ -34,7 +36,7 @@ public class OpenApiFileUtils {
@SuppressWarnings("unchecked")
public static Ddms getDmsWithOpenSpec(String filePath, String type) throws IOException {
File file = new File(Resources.getResource(filePath).getFile());
File file = readFile(filePath);
assertTrue("Could not find resource", file.exists());
ObjectMapper mapper = new ObjectMapper();
Map<String, Object> schema = mapper.readValue(file, HashMap.class);
......@@ -48,6 +50,16 @@ public class OpenApiFileUtils {
}
public static OpenApi3 getOpenApi(String filePath) throws Exception {
return (OpenApi3) new OpenApiParser().parse(Resources.getResource(filePath), true);
return (OpenApi3) new OpenApiParser().parse(readFile(filePath), true);
}
}
\ No newline at end of file
private static File readFile(String filepath) throws IOException {
URI uri = null;
try {
uri = OpenApiFileUtils.class.getClassLoader().getResource(filepath).toURI();
} catch (URISyntaxException e) {
throw new IOException();
}
return new File(uri);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment