Skip to content
This repository has been archived by the owner on Sep 23, 2023. It is now read-only.

Commit

Permalink
removed model class (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
dinuta committed Oct 8, 2020
1 parent de90a90 commit 7380db3
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 224 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import com.github.dinuta.estuary.agent.model.YamlConfig;
import com.github.dinuta.estuary.agent.model.api.ApiResponse;
import com.github.dinuta.estuary.agent.model.api.ApiResponseCommandDescription;
import com.github.dinuta.estuary.agent.model.api.ApiResponseConfigDescriptor;
import com.github.dinuta.estuary.agent.model.api.CommandDescription;
import com.github.dinuta.estuary.agent.utils.YamlConfigParser;
import org.apache.commons.io.IOUtils;
Expand Down Expand Up @@ -206,22 +205,25 @@ public void whenSendingTheCommandsConfigYamlApiReturnsTheCorrectDetailsForEachOn
YamlConfig yamlConfig = objectMapper.readValue(yamlConfigString, YamlConfig.class);
List<String> list = new YamlConfigParser().getCommandsList(yamlConfig);

ResponseEntity<ApiResponseConfigDescriptor> responseEntity =
ResponseEntity<ApiResponse> responseEntity =
getApiResponseConfigDescriptorResponseEntity(yamlConfigString);

ApiResponseConfigDescriptor body = responseEntity.getBody();
ApiResponse body = responseEntity.getBody();
CommandDescription commandDescription = objectMapperJson.readValue(
new JSONObject((Map) body.getConfigDescriptor().getDescription()).toJSONString(),
new JSONObject((Map) ((Map) body.getDescription()).get("description")).toJSONString(),
CommandDescription.class);
YamlConfig yamlConfigResponse = objectMapperJson.readValue(
new JSONObject((Map) ((Map) body.getDescription()).get("config")).toJSONString(),
YamlConfig.class);

assertThat(responseEntity.getStatusCode().value()).isEqualTo(HttpStatus.OK.value());
assertThat(body.getCode()).isEqualTo(ApiResponseConstants.SUCCESS);
assertThat(body.getMessage()).isEqualTo(String.format(ApiResponseMessage.getMessage(ApiResponseConstants.SUCCESS)));

assertThat(body.getConfigDescriptor().getYamlConfig().getEnv()).isEqualTo(yamlConfig.getEnv());
assertThat(body.getConfigDescriptor().getYamlConfig().getBeforeScript()).isEqualTo(yamlConfig.getBeforeScript());
assertThat(body.getConfigDescriptor().getYamlConfig().getScript()).isEqualTo(yamlConfig.getScript());
assertThat(body.getConfigDescriptor().getYamlConfig().getAfterScript()).isEqualTo(yamlConfig.getAfterScript());
assertThat(yamlConfigResponse.getEnv()).isEqualTo(yamlConfig.getEnv());
assertThat(yamlConfigResponse.getBeforeScript()).isEqualTo(yamlConfig.getBeforeScript());
assertThat(yamlConfigResponse.getScript()).isEqualTo(yamlConfig.getScript());
assertThat(yamlConfigResponse.getAfterScript()).isEqualTo(yamlConfig.getAfterScript());
assertThat(commandDescription.getCommands().get(list.get(0)).getDetails().getCode()).isEqualTo(0L);
assertThat(commandDescription.getCommands().get(list.get(1)).getDetails().getCode()).isEqualTo(0L);
assertThat(commandDescription.getCommands().get(list.get(2)).getDetails().getCode()).isEqualTo(0L);
Expand Down Expand Up @@ -292,14 +294,14 @@ private ResponseEntity<ApiResponseCommandDescription> getApiResponseCommandDescr
ApiResponseCommandDescription.class);
}

private ResponseEntity<ApiResponseConfigDescriptor> getApiResponseConfigDescriptorResponseEntity(String yamlConfig) {
private ResponseEntity<ApiResponse> getApiResponseConfigDescriptorResponseEntity(String yamlConfig) {
Map<String, String> headers = new HashMap<>();

return this.restTemplate
.exchange(SERVER_PREFIX + port + "/commandyaml",
HttpMethod.POST,
httpRequestUtils.getRequestEntityContentTypeAppJson(yamlConfig, headers),
ApiResponseConfigDescriptor.class);
ApiResponse.class);
}

private ResponseEntity<ApiResponse> getApiResponseResponseEntity(String yamlConfig) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
import com.github.dinuta.estuary.agent.model.YamlConfig;
import com.github.dinuta.estuary.agent.model.api.ApiResponse;
import com.github.dinuta.estuary.agent.model.api.ApiResponseCommandDescription;
import com.github.dinuta.estuary.agent.model.api.ApiResponseConfigDescriptor;
import com.github.dinuta.estuary.agent.utils.YamlConfigParser;
import org.apache.commons.io.IOUtils;
import org.json.simple.JSONObject;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.params.ParameterizedTest;
Expand Down Expand Up @@ -150,22 +150,28 @@ public void whenSendingTheCommandsConfigYamlApiReturnsTheCorrectDetailsForEachOn
String testId = "testIdYaml";
String yamlConfigString = IOUtils.toString(this.getClass().getResourceAsStream(YAML_CONFIG), "UTF-8");
ObjectMapper objectMapper = new ObjectMapper(new YAMLFactory()).findAndRegisterModules();
ObjectMapper objectMapperJson = new ObjectMapper();
YamlConfig yamlConfig = objectMapper.readValue(yamlConfigString, YamlConfig.class);
List<String> list = new YamlConfigParser().getCommandsList(yamlConfig);

ResponseEntity<ApiResponseConfigDescriptor> responseEntity = this.restTemplate
ResponseEntity<ApiResponse> responseEntity = this.restTemplate
.exchange(SERVER_PREFIX + port + "/commanddetachedyaml/" + testId,
HttpMethod.POST,
httpRequestUtils.getRequestEntityJsonContentTypeAppText(yamlConfigString, new HashMap<>()),
ApiResponseConfigDescriptor.class);
ApiResponse.class);

ApiResponse body = responseEntity.getBody();
String commandDescription = ((Map) body.getDescription()).get("description").toString();
YamlConfig yamlConfigResponse = objectMapperJson.readValue(
new JSONObject((Map) ((Map) body.getDescription()).get("config")).toJSONString(),
YamlConfig.class);

ApiResponseConfigDescriptor body = responseEntity.getBody();
assertThat(responseEntity.getStatusCode().value()).isEqualTo(HttpStatus.OK.value());
assertThat(body.getConfigDescriptor().getDescription().toString()).isEqualTo(testId);
assertThat(body.getConfigDescriptor().getYamlConfig().getEnv()).isEqualTo(yamlConfig.getEnv());
assertThat(body.getConfigDescriptor().getYamlConfig().getBeforeScript()).isEqualTo(yamlConfig.getBeforeScript());
assertThat(body.getConfigDescriptor().getYamlConfig().getScript()).isEqualTo(yamlConfig.getScript());
assertThat(body.getConfigDescriptor().getYamlConfig().getAfterScript()).isEqualTo(yamlConfig.getAfterScript());
assertThat(commandDescription).isEqualTo(testId);
assertThat(yamlConfigResponse.getEnv()).isEqualTo(yamlConfig.getEnv());
assertThat(yamlConfigResponse.getBeforeScript()).isEqualTo(yamlConfig.getBeforeScript());
assertThat(yamlConfigResponse.getScript()).isEqualTo(yamlConfig.getScript());
assertThat(yamlConfigResponse.getAfterScript()).isEqualTo(yamlConfig.getAfterScript());

await().atMost(2, SECONDS).until(isCommandFinished(list.get(0)));
ResponseEntity<ApiResponseCommandDescription> responseEntityCmdDescription =
Expand Down

0 comments on commit 7380db3

Please sign in to comment.