+ @Test
+ void putEiProducer() throws Exception {
+ String url = ProducerConsts.API_ROOT + "/eiproducers/eiProducerId";
+ String body = gson.toJson(producerEiRegistratioInfo());
+
+ ResponseEntity<String> resp = restClient().putForEntity(url, body).block();
+ assertThat(resp.getStatusCode()).isEqualTo(HttpStatus.CREATED);
+
+ assertThat(this.eiTypes.size()).isEqualTo(1);
+ EiType type = this.eiTypes.getType("typeId");
+ assertThat(type.getProducerIds().contains("eiProducerId")).isTrue();
+ assertThat(this.eiProducers.size()).isEqualTo(1);
+ assertThat(this.eiProducers.get("eiProducerId").eiTypes().iterator().next().getId().equals("typeId")).isTrue();
+
+ resp = restClient().putForEntity(url, body).block();
+ assertThat(resp.getStatusCode()).isEqualTo(HttpStatus.OK);
+ }
+
+ @Test
+ void putEiProducerExistingJob() throws Exception {
+ this.addEiJob("typeId", "jobId");
+ String url = ProducerConsts.API_ROOT + "/eiproducers/eiProducerId";
+ String body = gson.toJson(producerEiRegistratioInfo());
+
+ ResponseEntity<String> resp = restClient().putForEntity(url, body).block();
+ 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");
+ }
+
+ @Test
+ void getEiJobsForProducer() {
+ this.addEiJob("typeId", "jobId1");
+ this.addEiJob("typeId", "jobId2");
+
+ // PUT a consumer
+ String url = ProducerConsts.API_ROOT + "/eiproducers/eiProducerId";
+ String body = gson.toJson(producerEiRegistratioInfo());
+ restClient().putForEntity(url, body).block();
+
+ url = ProducerConsts.API_ROOT + "/eiproducers/eiProducerId/eijobs";
+ ResponseEntity<String> resp = restClient().getForEntity(url).block();
+ assertThat(resp.getStatusCode()).isEqualTo(HttpStatus.OK);
+
+ ProducerJobInfo[] parsedResp = gson.fromJson(resp.getBody(), ProducerJobInfo[].class);
+ assertThat(parsedResp[0].typeId).isEqualTo("typeId");
+ assertThat(parsedResp[1].typeId).isEqualTo("typeId");
+ }
+
+ @Test
+ void deleteEiProducer() throws Exception {
+ String url = ProducerConsts.API_ROOT + "/eiproducers/eiProducerId";
+ String url2 = ProducerConsts.API_ROOT + "/eiproducers/eiProducerId2";
+ String body = gson.toJson(producerEiRegistratioInfo());
+ restClient().putForEntity(url, body).block();
+ restClient().putForEntity(url2, body).block();
+ assertThat(this.eiProducers.size()).isEqualTo(2);
+ EiType type = this.eiTypes.getType("typeId");
+ assertThat(type.getProducerIds().contains("eiProducerId")).isTrue();
+ assertThat(type.getProducerIds().contains("eiProducerId2")).isTrue();
+
+ restClient().deleteForEntity(url).block();
+ assertThat(this.eiProducers.size()).isEqualTo(1);
+ assertThat(this.eiTypes.getType("typeId").getProducerIds().contains("eiProducerId")).isFalse();
+
+ restClient().deleteForEntity(url2).block();
+ assertThat(this.eiProducers.size()).isEqualTo(0);
+ assertThat(this.eiTypes.size()).isEqualTo(0);
+ }
+
+ ProducerEiTypeRegistrationInfo producerEiTypeRegistrationInfo() {
+ return new ProducerEiTypeRegistrationInfo(jsonObject(), "typeId");
+ }
+
+ ProducerRegistrationInfo producerEiRegistratioInfo() {
+ Collection<ProducerEiTypeRegistrationInfo> types = new ArrayList<>();
+ types.add(producerEiTypeRegistrationInfo());
+ return new ProducerRegistrationInfo(types, baseUrl() + ProducerSimulatorController.JOB_CREATED_URL,
+ baseUrl() + ProducerSimulatorController.JOB_DELETED_URL);
+ }
+
+ ConsumerEiJobInfo eiJobInfo() {
+ return new ConsumerEiJobInfo(jsonObject(), "owner");