X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=enrichment-coordinator-service%2Fsrc%2Ftest%2Fjava%2Forg%2Foransc%2Fenrichment%2FApplicationTest.java;h=9a731e6cbe02e857778f9f223bb66b0d5465ecef;hb=6a1eb6e2a6538decc54f5348fcb1589f5b829e68;hp=62eff1218fc0b60b74acd5635f69ea2d036f17a4;hpb=3a88e8f0f4ba125d7e0f802b0ada0303fe3e8c56;p=nonrtric.git diff --git a/enrichment-coordinator-service/src/test/java/org/oransc/enrichment/ApplicationTest.java b/enrichment-coordinator-service/src/test/java/org/oransc/enrichment/ApplicationTest.java index 62eff121..9a731e6c 100644 --- a/enrichment-coordinator-service/src/test/java/org/oransc/enrichment/ApplicationTest.java +++ b/enrichment-coordinator-service/src/test/java/org/oransc/enrichment/ApplicationTest.java @@ -45,6 +45,7 @@ import org.oransc.enrichment.configuration.WebClientConfig; import org.oransc.enrichment.controller.ProducerSimulatorController; import org.oransc.enrichment.controllers.consumer.ConsumerConsts; import org.oransc.enrichment.controllers.consumer.ConsumerEiJobInfo; +import org.oransc.enrichment.controllers.consumer.ConsumerEiTypeInfo; import org.oransc.enrichment.controllers.producer.ProducerConsts; import org.oransc.enrichment.controllers.producer.ProducerRegistrationInfo; import org.oransc.enrichment.controllers.producer.ProducerRegistrationInfo.ProducerEiTypeRegistrationInfo; @@ -146,7 +147,8 @@ class ApplicationTest { putEiProducerWithOneType(EI_PRODUCER_ID, "test"); String url = ConsumerConsts.API_ROOT + "/eitypes/test"; String rsp = restClient().get(url).block(); - assertThat(rsp).contains("job_data_schema"); + ConsumerEiTypeInfo info = gson.fromJson(rsp, ConsumerEiTypeInfo.class); + assertThat(info.jobParametersSchema).isNotNull(); } @Test @@ -176,7 +178,8 @@ class ApplicationTest { putEiJob(EI_TYPE_ID, "jobId"); String url = ConsumerConsts.API_ROOT + "/eitypes/typeId/eijobs/jobId"; String rsp = restClient().get(url).block(); - assertThat(rsp).contains("job_data"); + ConsumerEiJobInfo info = gson.fromJson(rsp, ConsumerEiJobInfo.class); + assertThat(info.owner).isEqualTo("owner"); } @Test @@ -220,7 +223,9 @@ class ApplicationTest { @Test void testPutEiJob() throws Exception { + // Test that one producer accepting a job is enough putEiProducerWithOneType(EI_PRODUCER_ID, EI_TYPE_ID); + putEiProducerWithOneTypeRejecting("simulateProducerError", EI_TYPE_ID); String url = ConsumerConsts.API_ROOT + "/eitypes/typeId/eijobs/jobId"; String body = gson.toJson(eiJobInfo()); @@ -233,12 +238,25 @@ class ApplicationTest { ProducerJobInfo request = simulatorResults.jobsStarted.get(0); assertThat(request.id).isEqualTo("jobId"); + assertThat(simulatorResults.noOfRejectedCreate).isEqualTo(1); + resp = restClient().putForEntity(url, body).block(); assertThat(resp.getStatusCode()).isEqualTo(HttpStatus.OK); EiJob job = this.eiJobs.getJob("jobId"); assertThat(job.owner()).isEqualTo("owner"); } + @Test + void putEiProducerWithOneType_rejecting() throws JsonMappingException, JsonProcessingException, ServiceException { + putEiProducerWithOneTypeRejecting("simulateProducerError", EI_TYPE_ID); + String url = ConsumerConsts.API_ROOT + "/eitypes/typeId/eijobs/jobId"; + String body = gson.toJson(eiJobInfo()); + testErrorCode(restClient().put(url, body), HttpStatus.CONFLICT, "Job not accepted by any producers"); + + ProducerSimulatorController.TestResults simulatorResults = this.producerSimulator.getTestResults(); + assertThat(simulatorResults.noOfRejectedCreate).isEqualTo(1); + } + @Test void testPutEiJob_jsonSchemavalidationError() throws Exception { putEiProducerWithOneType(EI_PRODUCER_ID, EI_TYPE_ID); @@ -249,7 +267,7 @@ class ApplicationTest { new ConsumerEiJobInfo(jsonObject("{ \"XXstring\" : \"value\" }"), "owner", "targetUri"); String body = gson.toJson(jobInfo); - testErrorCode(restClient().put(url, body), HttpStatus.NOT_FOUND, "Json validation failure"); + testErrorCode(restClient().put(url, body), HttpStatus.CONFLICT, "Json validation failure"); } @Test @@ -413,6 +431,14 @@ class ApplicationTest { return new ProducerEiTypeRegistrationInfo(jsonSchemaObject(), typeId); } + ProducerRegistrationInfo producerEiRegistratioInfoRejecting(String typeId) + throws JsonMappingException, JsonProcessingException { + Collection types = new ArrayList<>(); + types.add(producerEiTypeRegistrationInfo(typeId)); + return new ProducerRegistrationInfo(types, baseUrl() + ProducerSimulatorController.JOB_CREATED_ERROR_URL, + baseUrl() + ProducerSimulatorController.JOB_DELETED_ERROR_URL); + } + ProducerRegistrationInfo producerEiRegistratioInfo(String typeId) throws JsonMappingException, JsonProcessingException { Collection types = new ArrayList<>(); @@ -464,6 +490,15 @@ class ApplicationTest { return this.eiJobs.getJob(jobId); } + private EiType putEiProducerWithOneTypeRejecting(String producerId, String eiTypeId) + throws JsonMappingException, JsonProcessingException, ServiceException { + String url = ProducerConsts.API_ROOT + "/eiproducers/" + producerId; + String body = gson.toJson(producerEiRegistratioInfoRejecting(eiTypeId)); + + restClient().putForEntity(url, body).block(); + return this.eiTypes.getType(eiTypeId); + } + private EiType putEiProducerWithOneType(String producerId, String eiTypeId) throws JsonMappingException, JsonProcessingException, ServiceException { String url = ProducerConsts.API_ROOT + "/eiproducers/" + producerId;