@Test public void test_tl_number_generator_should_throw_id_generation_exception() { when(restTemplate.postForObject(Mockito.anyString(), Mockito.any(AckNoGenerationRequest.class), Mockito.any())) .thenReturn(resources.readResponse("idGenErrorResponse.json")); thrown.expect(IdGenerationException.class); idGenService.generate("ap.kurnool", "", "", new RequestInfo()); }
public String generate(final String tenantId, final String nameServiceTopic, final String formatServiceTopic, RequestInfo requestInfo) { StringBuilder url = new StringBuilder(); String ackNumber = null; url.append(propertiesManager.getIdGenServiceBasePathTopic()) .append(propertiesManager.getIdGenServiceCreatePathTopic()); List<AckIdRequest> idRequests = new ArrayList<>(); AckIdRequest idrequest = new AckIdRequest(); idrequest.setIdName(nameServiceTopic); idrequest.setTenantId(tenantId); idrequest.setFormat(formatServiceTopic); AckNoGenerationRequest idGeneration = new AckNoGenerationRequest(); idRequests.add(idrequest); idGeneration.setIdRequests(idRequests); idGeneration.setRequestInfo(requestInfo); String response = null; try { response = restTemplate.postForObject(url.toString(), idGeneration, String.class); } catch (Exception ex) { throw new IdGenerationException("Error While generating " + nameServiceTopic + " number", "Error While generating " + nameServiceTopic + " number", requestInfo); } Gson gson = new GsonBuilder().setPrettyPrinting().serializeNulls().create(); IdGenErrorRes errorResponse = gson.fromJson(response, IdGenErrorRes.class); AckNoGenerationResponse idResponse = gson.fromJson(response, AckNoGenerationResponse.class); if (!errorResponse.getErrors().isEmpty()) { throw new IdGenerationException("Error While generating " + nameServiceTopic + " number", "Error While generating " + nameServiceTopic + " number", requestInfo); } else if (idResponse.getResponseInfo() != null) { if (idResponse.getResponseInfo().getStatus().toString().equalsIgnoreCase("SUCCESSFUL")) { if (idResponse.getIdResponses() != null && idResponse.getIdResponses().size() > 0) ackNumber = idResponse.getIdResponses().get(0).getId(); } } return ackNumber; }
IdGenService { public String generate(final String tenantId, final String nameServiceTopic, final String formatServiceTopic, RequestInfo requestInfo) { StringBuilder url = new StringBuilder(); String ackNumber = null; url.append(propertiesManager.getIdGenServiceBasePathTopic()) .append(propertiesManager.getIdGenServiceCreatePathTopic()); List<AckIdRequest> idRequests = new ArrayList<>(); AckIdRequest idrequest = new AckIdRequest(); idrequest.setIdName(nameServiceTopic); idrequest.setTenantId(tenantId); idrequest.setFormat(formatServiceTopic); AckNoGenerationRequest idGeneration = new AckNoGenerationRequest(); idRequests.add(idrequest); idGeneration.setIdRequests(idRequests); idGeneration.setRequestInfo(requestInfo); String response = null; try { response = restTemplate.postForObject(url.toString(), idGeneration, String.class); } catch (Exception ex) { throw new IdGenerationException("Error While generating " + nameServiceTopic + " number", "Error While generating " + nameServiceTopic + " number", requestInfo); } Gson gson = new GsonBuilder().setPrettyPrinting().serializeNulls().create(); IdGenErrorRes errorResponse = gson.fromJson(response, IdGenErrorRes.class); AckNoGenerationResponse idResponse = gson.fromJson(response, AckNoGenerationResponse.class); if (!errorResponse.getErrors().isEmpty()) { throw new IdGenerationException("Error While generating " + nameServiceTopic + " number", "Error While generating " + nameServiceTopic + " number", requestInfo); } else if (idResponse.getResponseInfo() != null) { if (idResponse.getResponseInfo().getStatus().toString().equalsIgnoreCase("SUCCESSFUL")) { if (idResponse.getIdResponses() != null && idResponse.getIdResponses().size() > 0) ackNumber = idResponse.getIdResponses().get(0).getId(); } } return ackNumber; } }
IdGenService { public String generate(final String tenantId, final String nameServiceTopic, final String formatServiceTopic, RequestInfo requestInfo) { StringBuilder url = new StringBuilder(); String ackNumber = null; url.append(propertiesManager.getIdGenServiceBasePathTopic()) .append(propertiesManager.getIdGenServiceCreatePathTopic()); List<AckIdRequest> idRequests = new ArrayList<>(); AckIdRequest idrequest = new AckIdRequest(); idrequest.setIdName(nameServiceTopic); idrequest.setTenantId(tenantId); idrequest.setFormat(formatServiceTopic); AckNoGenerationRequest idGeneration = new AckNoGenerationRequest(); idRequests.add(idrequest); idGeneration.setIdRequests(idRequests); idGeneration.setRequestInfo(requestInfo); String response = null; try { response = restTemplate.postForObject(url.toString(), idGeneration, String.class); } catch (Exception ex) { throw new IdGenerationException("Error While generating " + nameServiceTopic + " number", "Error While generating " + nameServiceTopic + " number", requestInfo); } Gson gson = new GsonBuilder().setPrettyPrinting().serializeNulls().create(); IdGenErrorRes errorResponse = gson.fromJson(response, IdGenErrorRes.class); AckNoGenerationResponse idResponse = gson.fromJson(response, AckNoGenerationResponse.class); if (!errorResponse.getErrors().isEmpty()) { throw new IdGenerationException("Error While generating " + nameServiceTopic + " number", "Error While generating " + nameServiceTopic + " number", requestInfo); } else if (idResponse.getResponseInfo() != null) { if (idResponse.getResponseInfo().getStatus().toString().equalsIgnoreCase("SUCCESSFUL")) { if (idResponse.getIdResponses() != null && idResponse.getIdResponses().size() > 0) ackNumber = idResponse.getIdResponses().get(0).getId(); } } return ackNumber; }  }
IdGenService { public String generate(final String tenantId, final String nameServiceTopic, final String formatServiceTopic, RequestInfo requestInfo) { StringBuilder url = new StringBuilder(); String ackNumber = null; url.append(propertiesManager.getIdGenServiceBasePathTopic()) .append(propertiesManager.getIdGenServiceCreatePathTopic()); List<AckIdRequest> idRequests = new ArrayList<>(); AckIdRequest idrequest = new AckIdRequest(); idrequest.setIdName(nameServiceTopic); idrequest.setTenantId(tenantId); idrequest.setFormat(formatServiceTopic); AckNoGenerationRequest idGeneration = new AckNoGenerationRequest(); idRequests.add(idrequest); idGeneration.setIdRequests(idRequests); idGeneration.setRequestInfo(requestInfo); String response = null; try { response = restTemplate.postForObject(url.toString(), idGeneration, String.class); } catch (Exception ex) { throw new IdGenerationException("Error While generating " + nameServiceTopic + " number", "Error While generating " + nameServiceTopic + " number", requestInfo); } Gson gson = new GsonBuilder().setPrettyPrinting().serializeNulls().create(); IdGenErrorRes errorResponse = gson.fromJson(response, IdGenErrorRes.class); AckNoGenerationResponse idResponse = gson.fromJson(response, AckNoGenerationResponse.class); if (!errorResponse.getErrors().isEmpty()) { throw new IdGenerationException("Error While generating " + nameServiceTopic + " number", "Error While generating " + nameServiceTopic + " number", requestInfo); } else if (idResponse.getResponseInfo() != null) { if (idResponse.getResponseInfo().getStatus().toString().equalsIgnoreCase("SUCCESSFUL")) { if (idResponse.getIdResponses() != null && idResponse.getIdResponses().size() > 0) ackNumber = idResponse.getIdResponses().get(0).getId(); } } return ackNumber; }  String generate(final String tenantId, final String nameServiceTopic, final String formatServiceTopic,
			RequestInfo requestInfo); }
IdGenService { public String generate(final String tenantId, final String nameServiceTopic, final String formatServiceTopic, RequestInfo requestInfo) { StringBuilder url = new StringBuilder(); String ackNumber = null; url.append(propertiesManager.getIdGenServiceBasePathTopic()) .append(propertiesManager.getIdGenServiceCreatePathTopic()); List<AckIdRequest> idRequests = new ArrayList<>(); AckIdRequest idrequest = new AckIdRequest(); idrequest.setIdName(nameServiceTopic); idrequest.setTenantId(tenantId); idrequest.setFormat(formatServiceTopic); AckNoGenerationRequest idGeneration = new AckNoGenerationRequest(); idRequests.add(idrequest); idGeneration.setIdRequests(idRequests); idGeneration.setRequestInfo(requestInfo); String response = null; try { response = restTemplate.postForObject(url.toString(), idGeneration, String.class); } catch (Exception ex) { throw new IdGenerationException("Error While generating " + nameServiceTopic + " number", "Error While generating " + nameServiceTopic + " number", requestInfo); } Gson gson = new GsonBuilder().setPrettyPrinting().serializeNulls().create(); IdGenErrorRes errorResponse = gson.fromJson(response, IdGenErrorRes.class); AckNoGenerationResponse idResponse = gson.fromJson(response, AckNoGenerationResponse.class); if (!errorResponse.getErrors().isEmpty()) { throw new IdGenerationException("Error While generating " + nameServiceTopic + " number", "Error While generating " + nameServiceTopic + " number", requestInfo); } else if (idResponse.getResponseInfo() != null) { if (idResponse.getResponseInfo().getStatus().toString().equalsIgnoreCase("SUCCESSFUL")) { if (idResponse.getIdResponses() != null && idResponse.getIdResponses().size() > 0) ackNumber = idResponse.getIdResponses().get(0).getId(); } } return ackNumber; }  String generate(final String tenantId, final String nameServiceTopic, final String formatServiceTopic,
			RequestInfo requestInfo);  }