Skip to content

Commit

Permalink
Story-898 Task-4684: Addressed issue where generated input paths are …
Browse files Browse the repository at this point in the history
…erroneously being used as Input Path (#143)

* task-4684: addressed issue where generated input classes are being used as input path

* task-4684: addressed comments

* task-4684: addressed further comments

* task-4684: addressed further comments x2
  • Loading branch information
Chuks-Ajeh authored Jun 21, 2024
1 parent aaec9b7 commit fee016f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand Down Expand Up @@ -71,11 +71,11 @@ public class TestPackConfigCreatorImpl implements TestPackConfigCreator {
/**
* Generates pipeline and test-pack config files.
*
* @param rosettaPaths - list of folders that contain rosetta model files, e.g. "drr/rosetta"
* @param filter - provides filters to include or exclude
* @param testPackDefs - provides list of test-pack information such as test pack name, input type and sample input paths
* @param outputSchemaMap - output Document type / xsd look up map
* @param injector - model runtime guice injector
* @param rosettaPaths - list of folders that contain rosetta model files, e.g. "drr/rosetta"
* @param filter - provides filters to include or exclude
* @param testPackDefs - provides list of test-pack information such as test pack name, input type and sample input paths
* @param outputSchemaMap - output Document type / xsd look up map
* @param injector - model runtime guice injector
*/
@Override
public void createPipelineAndTestPackConfig(ImmutableList<String> rosettaPaths,
Expand Down Expand Up @@ -261,6 +261,7 @@ protected TestPackModel createReportTestPack(TestPackDef testPack, RosettaReport
String displayName = baseFileName.replace("-", " ");

Pair<String, Assertions> result = functionRunner.run(inputPath);

writeOutputFile(outputPath, result.left());
Assertions assertions = result.right();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand All @@ -22,7 +22,6 @@

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectWriter;
import com.google.common.io.Resources;
import com.regnosys.rosetta.common.hashing.ReferenceConfig;
import com.regnosys.rosetta.common.hashing.ReferenceResolverProcessStep;
import com.regnosys.rosetta.common.util.Pair;
Expand All @@ -39,6 +38,7 @@
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.nio.file.Path;
Expand All @@ -50,7 +50,8 @@

class TestPackFunctionRunnerImpl<IN extends RosettaModelObject> implements TestPackFunctionRunner {
private static final Logger LOGGER = LoggerFactory.getLogger(TestPackFunctionRunnerImpl.class);

public static final Path ROSETTA_SOURCE_PATH = Path.of("rosetta-source/src/main/resources/");

private final Function<IN, RosettaModelObject> function;
private final Class<IN> inputType;
private final RosettaTypeValidator typeValidator;
Expand All @@ -75,11 +76,15 @@ public TestPackFunctionRunnerImpl(Function<IN, RosettaModelObject> function,

@Override
public Pair<String, Assertions> run(Path inputPath) {
URL inputFileUrl = Resources.getResource(inputPath.toString());
IN input = readFile(inputFileUrl, JSON_OBJECT_MAPPER, inputType);
RosettaModelObject output;
try {
Path inputPathFromRepositoryRoot = ROSETTA_SOURCE_PATH.resolve(inputPath);
URL inputFileUrl = inputPathFromRepositoryRoot.toUri().toURL();
IN input = readFile(inputFileUrl, JSON_OBJECT_MAPPER, inputType);
output = function.apply(resolveReferences(input));
} catch (MalformedURLException e) {
LOGGER.error("Failed to load input path {}", inputPath, e);
return Pair.of(null, new Assertions(null, null, true));
} catch (Exception e) {
LOGGER.error("Exception occurred running sample creation", e);
return Pair.of(null, new Assertions(null, null, true));
Expand All @@ -97,11 +102,11 @@ public Pair<String, Assertions> run(Path inputPath) {
int actualValidationFailures = validationReport.validationFailures().size();

Boolean schemaValidationFailure = isSchemaValidationFailure(serialisedOutput);

Assertions assertions = new Assertions(actualValidationFailures, schemaValidationFailure, false);
return Pair.of(serialisedOutput, assertions);
}

private <T extends RosettaModelObject> T resolveReferences(T o) {
RosettaModelObjectBuilder builder = o.toBuilder();
new ReferenceResolverProcessStep(referenceConfig).runProcessStep(o.getType(), builder);
Expand Down

0 comments on commit fee016f

Please sign in to comment.