Skip to content

Commit

Permalink
Merge branch 'fix-test-clients' of https://github.com/FINTprosjektet/…
Browse files Browse the repository at this point in the history
…fint-provider into fix-test-clients
  • Loading branch information
jarlehansen committed Oct 25, 2018
2 parents d766b98 + 6eb2660 commit fec2442
Show file tree
Hide file tree
Showing 8 changed files with 91 additions and 19 deletions.
13 changes: 0 additions & 13 deletions .travis.yml

This file was deleted.

2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM gradle:4.2.1-jdk8-alpine as builder
FROM gradle:4.9.0-jdk8-alpine as builder
USER root
COPY . .
RUN gradle --no-daemon build
Expand Down
15 changes: 15 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,20 @@ pipeline {
}
}
}
stage('Coverage') {
agent {
docker {
label 'docker'
image 'gradle:4.9.0-jdk8-alpine'
}
}
environment {
COVERALLS_REPO_TOKEN = "9AOqHwDAKkTQGoKNX1e1dj88fxJXgZe2z"
INTEGRATION = true
}
steps {
sh 'gradle --no-daemon test jacocoTestReport coveralls'
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,16 @@ public void onEvent(Event event) {
private void postStatus(Event event) {
HttpHeaders headers = new HttpHeaders();
headers.put(HeaderConstants.ORG_ID, Lists.newArrayList(event.getOrgId()));
ResponseEntity<Void> response = restTemplate.exchange("http://localhost:8080/provider/status", HttpMethod.POST, new HttpEntity<>(event, headers), Void.class);
ResponseEntity<Void> response = restTemplate.exchange("http://localhost:{port}/{context}/status",
HttpMethod.POST, new HttpEntity<>(event, headers), Void.class, port, contextPath);
log.info("Provider POST response: {}", response.getStatusCode());
}

private void postResponse(Event event) {
HttpHeaders headers = new HttpHeaders();
headers.put(HeaderConstants.ORG_ID, Lists.newArrayList(event.getOrgId()));
ResponseEntity<Void> response = restTemplate.exchange("http://localhost:8080/provider/response", HttpMethod.POST, new HttpEntity<>(event, headers), Void.class);
ResponseEntity<Void> response = restTemplate.exchange("http://localhost:{port}/{context}/response",
HttpMethod.POST, new HttpEntity<>(event, headers), Void.class, port, contextPath);
log.info("Provider POST response: {}", response.getStatusCode());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class TestModeController implements FintEventListener {
public void init() {
log.info("Test mode enabled, starting consumer");
fintEvents.registerUpstreamListener(TestModeConstants.ORGID, this);
fintEvents.registerUpstreamSystemListener(this);
fintEvents.registerUpstreamSystemListener((event -> log.info("Received system event: {}", event)));
}

@PostMapping
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/application-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ fint:
hazelcast:
members: localhost
provider:
assets:
endpoint: https://admin.fintlabs.no/api/components/assets/administrasjon_personal
test-mode: true
sse:
maxPoolSize: 10
queueCapacity: 0
audit:
test-mode: true
events:
test-mode: true
queue-endpoint-enabled: true
springfox:
swagger-https: false
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package no.fint.provider.events.testmode

import no.fint.provider.events.testmode.adapter.TestModeAdapter
import no.fint.provider.events.testmode.consumer.TestModeController
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.context.SpringBootTest
import spock.lang.Specification

@SpringBootTest
class TestModeDisabledSpec extends Specification {

@Autowired(required = false)
private TestModeController controller

@Autowired(required = false)
private TestModeAdapter adapter

def "Test mode components are disabled by default"() {
expect:
!controller
!adapter
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package no.fint.provider.events.testmode

import no.fint.provider.events.Application
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.beans.factory.annotation.Value
import org.springframework.boot.context.embedded.LocalServerPort
import org.springframework.boot.test.context.SpringBootTest
import org.springframework.boot.test.web.client.TestRestTemplate
import org.springframework.test.context.ActiveProfiles
import spock.lang.Requires
import spock.lang.Specification

import java.util.concurrent.TimeUnit

@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT, classes = Application)
@ActiveProfiles('local')
@Requires({ env.INTEGRATION })
class TestModeSpec extends Specification {

@LocalServerPort
private int port

@Value('${server.context-path:/}')
private String contextPath

@Autowired
private TestRestTemplate restTemplate

def 'Loopback events'() {
when:
TimeUnit.SECONDS.sleep(10)
def response1 = restTemplate.postForEntity('http://localhost:{port}/{context}/test-mode-consumer?numberOfEvents={events}', null, Void, port, contextPath, 10)

then:
response1.statusCode.is2xxSuccessful()

when:
TimeUnit.SECONDS.sleep(10)
def response2 = restTemplate.getForEntity('http://localhost:{port}/{context}/test-mode-consumer', Map, port, contextPath)

then:
response2.statusCode.is2xxSuccessful()
response2.body['numberOfEvents'] == 10
}
}

0 comments on commit fec2442

Please sign in to comment.