+ @Test
+ void a1eDeleteEiJob() throws Exception {
+ putInfoProducerWithOneType(PRODUCER_ID, TYPE_ID);
+ putEiJob(TYPE_ID, "jobId");
+ assertThat(this.infoJobs.size()).isEqualTo(1);
+ String url = A1eConsts.API_ROOT + "/eijobs/jobId";
+ restClient().delete(url).block();
+ assertThat(this.infoJobs.size()).isZero();
+
+ ProducerSimulatorController.TestResults simulatorResults = this.producerSimulator.getTestResults();
+ await().untilAsserted(() -> assertThat(simulatorResults.jobsStopped.size()).isEqualTo(1));
+ assertThat(simulatorResults.jobsStopped.get(0)).isEqualTo("jobId");
+ }
+
+ @Test
+ void consumerDeleteEiJob() throws Exception {
+ putInfoProducerWithOneType(PRODUCER_ID, TYPE_ID);
+ putEiJob(TYPE_ID, "jobId");
+ assertThat(this.infoJobs.size()).isEqualTo(1);
+ String url = ConsumerConsts.API_ROOT + "/info-jobs/jobId";
+ restClient().delete(url).block();
+ assertThat(this.infoJobs.size()).isZero();
+
+ ProducerSimulatorController.TestResults simulatorResults = this.producerSimulator.getTestResults();
+ await().untilAsserted(() -> assertThat(simulatorResults.jobsStopped.size()).isEqualTo(1));
+ assertThat(simulatorResults.jobsStopped.get(0)).isEqualTo("jobId");
+ }
+
+ @Test
+ void a1eDeleteEiJobNotFound() throws Exception {
+ putInfoProducerWithOneType(PRODUCER_ID, TYPE_ID);
+ String url = A1eConsts.API_ROOT + "/eijobs/junk";
+ testErrorCode(restClient().get(url), HttpStatus.NOT_FOUND, "Could not find Information job: junk");
+ }
+
+ @Test
+ void consumerDeleteEiJobNotFound() throws Exception {
+ putInfoProducerWithOneType(PRODUCER_ID, TYPE_ID);
+ String url = ConsumerConsts.API_ROOT + "/info-jobs/junk";
+ testErrorCode(restClient().get(url), HttpStatus.NOT_FOUND, "Could not find Information job: junk");
+ }
+
+ @Test
+ void a1ePutEiJob() throws Exception {
+ // Test that one producer accepting a job is enough
+ putInfoProducerWithOneType(PRODUCER_ID, TYPE_ID);
+ putEiProducerWithOneTypeRejecting("simulateProducerError", TYPE_ID);
+
+ String url = A1eConsts.API_ROOT + "/eijobs/jobId";
+ String body = gson.toJson(infoJobInfo());
+ ResponseEntity<String> resp = restClient().putForEntity(url, body).block();
+ assertThat(this.infoJobs.size()).isEqualTo(1);
+ assertThat(resp.getStatusCode()).isEqualTo(HttpStatus.CREATED);
+
+ ProducerSimulatorController.TestResults simulatorResults = this.producerSimulator.getTestResults();
+ await().untilAsserted(() -> assertThat(simulatorResults.jobsStarted.size()).isEqualTo(1));
+ ProducerJobInfo request = simulatorResults.jobsStarted.get(0);
+ assertThat(request.id).isEqualTo("jobId");
+
+ // One retry --> two calls
+ await().untilAsserted(() -> assertThat(simulatorResults.noOfRejectedCreate).isEqualTo(2));
+ assertThat(simulatorResults.noOfRejectedCreate).isEqualTo(2);
+
+ resp = restClient().putForEntity(url, body).block();
+ assertThat(resp.getStatusCode()).isEqualTo(HttpStatus.OK);
+ InfoJob job = this.infoJobs.getJob("jobId");
+ assertThat(job.getOwner()).isEqualTo("owner");
+
+ verifyJobStatus(EI_JOB_ID, "ENABLED");
+ }
+
+ @Test
+ void consumerPutInformationJob() throws Exception {
+ // Test that one producer accepting a job is enough
+ putInfoProducerWithOneType(PRODUCER_ID, TYPE_ID);
+
+ String url = ConsumerConsts.API_ROOT + "/info-jobs/jobId";
+ String body = gson.toJson(consumerJobInfo());
+ ResponseEntity<String> resp = restClient().putForEntity(url, body).block();
+ assertThat(this.infoJobs.size()).isEqualTo(1);
+ assertThat(resp.getStatusCode()).isEqualTo(HttpStatus.CREATED);
+
+ ProducerSimulatorController.TestResults simulatorResults = this.producerSimulator.getTestResults();
+ await().untilAsserted(() -> assertThat(simulatorResults.jobsStarted.size()).isEqualTo(1));
+ ProducerJobInfo request = simulatorResults.jobsStarted.get(0);
+ assertThat(request.id).isEqualTo("jobId");
+
+ resp = restClient().putForEntity(url, body).block();
+ assertThat(resp.getStatusCode()).isEqualTo(HttpStatus.OK);
+ InfoJob job = this.infoJobs.getJob("jobId");
+ assertThat(job.getOwner()).isEqualTo("owner");
+
+ verifyJobStatus(EI_JOB_ID, "ENABLED");
+ }
+
+ @Test
+ void consumerPutInformationJob_noType() throws JsonMappingException, JsonProcessingException, ServiceException {
+ String url = ConsumerConsts.API_ROOT + "/info-jobs/jobId?typeCheck=false";
+ String body = gson.toJson(consumerJobInfo());
+ ResponseEntity<String> resp = restClient().putForEntity(url, body).block();
+ assertThat(this.infoJobs.size()).isEqualTo(1);
+ assertThat(resp.getStatusCode()).isEqualTo(HttpStatus.CREATED);
+ verifyJobStatus(EI_JOB_ID, "DISABLED");
+
+ putInfoProducerWithOneType(PRODUCER_ID, TYPE_ID);
+
+ verifyJobStatus(EI_JOB_ID, "ENABLED");
+
+ }
+
+ @Test
+ void a1ePutEiJob_jsonSchemavalidationError() throws Exception {
+ putInfoProducerWithOneType(PRODUCER_ID, TYPE_ID);
+
+ String url = A1eConsts.API_ROOT + "/eijobs/jobId";
+ // The element with name "property1" is mandatory in the schema
+ A1eEiJobInfo jobInfo = new A1eEiJobInfo("typeId", jsonObject("{ \"XXstring\" : \"value\" }"), "owner",
+ "targetUri", "jobStatusUrl");
+ String body = gson.toJson(jobInfo);
+
+ testErrorCode(restClient().put(url, body), HttpStatus.CONFLICT, "Json validation failure");
+ }
+
+ @Test
+ void consumerPutJob_jsonSchemavalidationError() throws Exception {
+ putInfoProducerWithOneType(PRODUCER_ID, TYPE_ID);
+
+ String url = ConsumerConsts.API_ROOT + "/info-jobs/jobId?typeCheck=true";
+ // The element with name "property1" is mandatory in the schema
+ ConsumerJobInfo jobInfo =
+ new ConsumerJobInfo("typeId", jsonObject("{ \"XXstring\" : \"value\" }"), "owner", "targetUri", null);
+ String body = gson.toJson(jobInfo);
+
+ testErrorCode(restClient().put(url, body), HttpStatus.CONFLICT, "Json validation failure");
+ }
+
+ @Test
+ void consumerPutJob_uriError() throws Exception {
+ putInfoProducerWithOneType(PRODUCER_ID, TYPE_ID);
+
+ String url = ConsumerConsts.API_ROOT + "/info-jobs/jobId?typeCheck=true";
+
+ ConsumerJobInfo jobInfo = new ConsumerJobInfo(TYPE_ID, jsonObject(), "owner", "junk", null);
+ String body = gson.toJson(jobInfo);
+
+ testErrorCode(restClient().put(url, body), HttpStatus.CONFLICT, "URI: junk is not absolute");
+ }
+
+ @Test
+ void a1eChangingEiTypeGetRejected() throws Exception {
+ putInfoProducerWithOneType("producer1", "typeId1");
+ putInfoProducerWithOneType("producer2", "typeId2");
+ putEiJob("typeId1", "jobId");
+
+ String url = A1eConsts.API_ROOT + "/eijobs/jobId";
+ String body = gson.toJson(infoJobInfo("typeId2", "jobId"));
+ testErrorCode(restClient().put(url, body), HttpStatus.CONFLICT,
+ "Not allowed to change type for existing EI job");
+ }
+
+ @Test
+ void consumerChangingInfoTypeGetRejected() throws Exception {
+ putInfoProducerWithOneType("producer1", "typeId1");
+ putInfoProducerWithOneType("producer2", "typeId2");
+ putEiJob("typeId1", "jobId");
+
+ String url = ConsumerConsts.API_ROOT + "/info-jobs/jobId";
+ String body = gson.toJson(consumerJobInfo("typeId2", "jobId"));
+ testErrorCode(restClient().put(url, body), HttpStatus.CONFLICT, "Not allowed to change type for existing job");
+ }
+
+ @Test
+ void producerPutEiType() throws JsonMappingException, JsonProcessingException, ServiceException {
+ assertThat(putInfoType(TYPE_ID)).isEqualTo(HttpStatus.CREATED);
+ assertThat(putInfoType(TYPE_ID)).isEqualTo(HttpStatus.OK);
+ }
+
+ @Test
+ void producerPutEiType_noSchema() {
+ String url = ProducerConsts.API_ROOT + "/info-types/" + TYPE_ID;
+ String body = "{}";
+ testErrorCode(restClient().put(url, body), HttpStatus.BAD_REQUEST, "No schema provided");
+ }