From 70dc84c98a4731a01659838b64a848057ce539dc Mon Sep 17 00:00:00 2001 From: Dmitriy Kopylenko Date: Tue, 21 Jan 2020 13:41:10 -0500 Subject: [PATCH] Address code review --- beacon/core/build.gradle | 23 ++++++++-- .../tap/beacon/DefaultBeaconPublisher.java | 4 +- .../beacon/DefaultBeaconPublisherTests.groovy | 45 +++++++++++++++++++ .../beacon/DefaultBeaconPublisherTests.java | 39 ---------------- 4 files changed, 67 insertions(+), 44 deletions(-) create mode 100644 beacon/core/src/test/groovy/edu/internet2/tap/beacon/DefaultBeaconPublisherTests.groovy delete mode 100644 beacon/core/src/test/java/edu/internet2/tap/beacon/DefaultBeaconPublisherTests.java diff --git a/beacon/core/build.gradle b/beacon/core/build.gradle index f2cd35c58..778c9ec97 100644 --- a/beacon/core/build.gradle +++ b/beacon/core/build.gradle @@ -1,4 +1,11 @@ -apply plugin: 'java' +import org.springframework.boot.gradle.plugin.SpringBootPlugin + +plugins { + id 'org.springframework.boot' version '2.0.0.RELEASE' apply false + id 'io.spring.dependency-management' version '1.0.6.RELEASE' +} + +apply plugin: 'groovy' sourceCompatibility = 1.8 targetCompatibility = 1.8 @@ -6,7 +13,17 @@ repositories { jcenter() } +dependencyManagement { + imports { + mavenBom SpringBootPlugin.BOM_COORDINATES + } +} + dependencies { + testCompile "org.springframework.boot:spring-boot-starter-test" + testCompile "org.spockframework:spock-core:1.1-groovy-2.4" + testCompile "org.spockframework:spock-spring:1.1-groovy-2.4" + testCompile 'org.junit.jupiter:junit-jupiter-api:5.5.2' testCompile 'org.junit.jupiter:junit-jupiter-engine:5.5.2' } @@ -15,6 +32,6 @@ jar { archiveName = "beacon-core-${version}.jar" } -test { +/*test { useJUnitPlatform() -} \ No newline at end of file +}*/ \ No newline at end of file diff --git a/beacon/core/src/main/java/edu/internet2/tap/beacon/DefaultBeaconPublisher.java b/beacon/core/src/main/java/edu/internet2/tap/beacon/DefaultBeaconPublisher.java index e8061268c..eb077ddc9 100644 --- a/beacon/core/src/main/java/edu/internet2/tap/beacon/DefaultBeaconPublisher.java +++ b/beacon/core/src/main/java/edu/internet2/tap/beacon/DefaultBeaconPublisher.java @@ -24,9 +24,9 @@ */ public class DefaultBeaconPublisher implements BeaconPublisher { - private URL endpointUrl; + private final URL endpointUrl; - private String jsonPayload; + private final String jsonPayload; public DefaultBeaconPublisher(Map beaconDetails) { //Do data validation checks here. If any of the necessary beacon data not available here, throw a Runtime exception diff --git a/beacon/core/src/test/groovy/edu/internet2/tap/beacon/DefaultBeaconPublisherTests.groovy b/beacon/core/src/test/groovy/edu/internet2/tap/beacon/DefaultBeaconPublisherTests.groovy new file mode 100644 index 000000000..d3004ef13 --- /dev/null +++ b/beacon/core/src/test/groovy/edu/internet2/tap/beacon/DefaultBeaconPublisherTests.groovy @@ -0,0 +1,45 @@ +package edu.internet2.tap.beacon + +import spock.lang.Specification +import sun.security.x509.OtherName + +class DefaultBeaconPublisherTests extends Specification { + + def "DefaultBeaconPublisher invariants are enforced during object creation - null Map is passed"() { + when: + new DefaultBeaconPublisher(null) + + then: + thrown IllegalArgumentException + + } + + def "DefaultBeaconPublisher invariants are enforced during object creation - empty Map is passed"() { + when: + new DefaultBeaconPublisher([:]) + + then: + thrown IllegalArgumentException + } + + def "DefaultBeaconPublisher invariants are enforced during object creation - valid Beacon data Map is passed"() { + when: + def expectedJsonPaylaod = """{"msgType":"TIERBEACON", "tbMaintainer":"unittest_maintainer", "msgName":"TIER", "tbProduct":"image", "msgVersion":"1.0", "tbProductVersion":"v1", "tbTIERRelease":"tv1"}""" + + def configuredBeaconData = [LOGHOST : 'collector.testbed.tier.internet2.edu', + LOGPORT : '5001', + IMAGE : 'image', + VERSION : 'v1', + TIERVERSION: 'tv1', + MAINTAINER : 'unittest_maintainer'] + def p = new DefaultBeaconPublisher(configuredBeaconData) + println p.jsonPayload + + then: + noExceptionThrown() + p.endpointUri == 'http://collector.testbed.tier.internet2.edu:5001' + p.jsonPayload == expectedJsonPaylaod + + } + +} diff --git a/beacon/core/src/test/java/edu/internet2/tap/beacon/DefaultBeaconPublisherTests.java b/beacon/core/src/test/java/edu/internet2/tap/beacon/DefaultBeaconPublisherTests.java deleted file mode 100644 index 86c8b2edd..000000000 --- a/beacon/core/src/test/java/edu/internet2/tap/beacon/DefaultBeaconPublisherTests.java +++ /dev/null @@ -1,39 +0,0 @@ -package edu.internet2.tap.beacon; - -import org.junit.jupiter.api.Test; - -import java.util.HashMap; -import java.util.Map; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertThrows; - -public class DefaultBeaconPublisherTests { - - @Test - public void checkCorrectInvariantsWithBeaconDataNull() { - assertThrows(IllegalArgumentException.class, () -> new DefaultBeaconPublisher(null)); - } - - @Test - public void checkCorrectInvariantsWithBeaconDataEmpty() { - assertThrows(IllegalArgumentException.class, () -> new DefaultBeaconPublisher(new HashMap<>())); - } - - @Test - public void checkCorrectInvariantsWithValidBeaconData() { - String expectedJsonPayload = "{\"msgType\":\"TIERBEACON\", \"tbMaintainer\":\"unittest_maintainer\", \"msgName\":\"TIER\", \"tbProduct\":\"image\", \"msgVersion\":\"1.0\", \"tbProductVersion\":\"v1\", \"tbTIERRelease\":\"tv1\"}"; - - Map beaconData = new HashMap<>(); - beaconData.put("LOGHOST", "collector.testbed.tier.internet2.edu"); - beaconData.put("LOGPORT", "5001"); - beaconData.put("IMAGE", "image"); - beaconData.put("VERSION", "v1"); - beaconData.put("TIERVERSION", "tv1"); - beaconData.put("MAINTAINER", "unittest_maintainer"); - DefaultBeaconPublisher p = new DefaultBeaconPublisher(beaconData); - - assertEquals("http://collector.testbed.tier.internet2.edu:5001", p.getEndpointUri()); - assertEquals(expectedJsonPayload, p.getJsonPayload()); - } -}