Skip to content

Commit

Permalink
Changed GET /interrelationship/{environment} to return null as public…
Browse files Browse the repository at this point in the history
…ationTime in case of no contracts published for service
  • Loading branch information
wlodarcp committed Aug 24, 2021
1 parent fdbeca1 commit b1f8ae3
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import lombok.experimental.Delegate;

import java.time.Instant;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
Expand Down Expand Up @@ -39,6 +40,14 @@ public ServiceContracts(ServiceId id, List<Capability> capabilities, List<Expect
this.publicationTime = publicationTime;
}

public static ServiceContracts withEmptyContracts(ServiceId id) {
return new ServiceContracts(
id,
new ArrayList<>(),
new ArrayList<>(),
null);
}

public <C> Optional<C> getMappedCapabilities(String communicationInterface, Function<String, C> deserializer) {
return this.capabilities.stream()
.filter(capability -> capability.getProtocol().equals(communicationInterface))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,8 @@ public InterrelationshipDto getInterrelationship(@PathVariable("environment") St
}

private ServiceContracts getServiceContracts(ServiceId serviceId) {
return serviceContractsRepository.findOne(new ServiceId(serviceId.getName(), serviceId.getVersion()))
.orElseGet(() ->
new ServiceContracts(
new ServiceId(serviceId.getName(), serviceId.getVersion()),
new ArrayList<>(),
new ArrayList<>()));
return serviceContractsRepository.findOne(serviceId)
.orElseGet(() -> ServiceContracts.withEmptyContracts(serviceId));
}

private Set<ServiceId> getServicesIds(String environmentName) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import org.springframework.test.context.jdbc.Sql

import static com.hltech.judged.server.FileHelper.loadFromFileAndFormat

@Sql
@FunctionalTest
class InterrelationshipControllerFT extends PostgresDatabaseSpecification {

@LocalServerPort
int serverPort

def "should get interrelationship for selected environment"() {
@Sql('InterrelationshipControllerFT.WithContracts.sql')
def 'should get interrelationship for selected environment for service with published contracts'() {
given:
def environmentName = 'TEST'

Expand All @@ -36,13 +36,39 @@ class InterrelationshipControllerFT extends PostgresDatabaseSpecification {
response['environment'] == 'TEST'
response['serviceContracts'][0]['name'] == 'test-service'
response['serviceContracts'][0]['version'] == "1.0"
response['serviceContracts'][0]['publication-time']
response['serviceContracts'][0]['capabilities']['rest']['mimeType'] == "application/json"
response['serviceContracts'][0]['capabilities']['rest']['value'] == capabilities
response['serviceContracts'][0]['expectations']['test-service']['rest']['mimeType'] == "application/json"
response['serviceContracts'][0]['expectations']['test-service']['rest']['value'] == expectations
}

def "should return 404 if get selected environment doesn't exists"() {
@Sql('InterrelationshipControllerFT.WithoutContracts.sql')
def 'should get interrelationship for selected environment for service without published contracts'() {
given:
def environmentName = 'TEST'

when:
def response = RestAssured.given()
.port(serverPort)
.contentType("application/json")
.when()
.get("/interrelationship/${environmentName}")
.then()
.statusCode(200)
.contentType("application/json")
.extract().body().jsonPath().getMap('$')

then:
response['environment'] == 'TEST'
response['serviceContracts'][0]['name'] == 'test-service'
response['serviceContracts'][0]['version'] == "1.0"
response['serviceContracts'][0]['publication-time'] == null
response['serviceContracts'][0]['capabilities']['rest']['value'] == []
response['serviceContracts'][0]['expectations']['test-service']['rest']['value'] == []
}

def 'should return 404 if get selected environment doesn`t exists'() {
expect:
RestAssured.given()
.port(serverPort)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
INSERT INTO "public".service_versions (name, version, space, environment_name) VALUES ('test-service', '1.0', 'default' ,'TEST');
INSERT INTO "public".environments (name) VALUES ('TEST');

0 comments on commit b1f8ae3

Please sign in to comment.