Skip to content

Commit

Permalink
Add missing JavaDocs.
Browse files Browse the repository at this point in the history
Signed-off-by: Kai Hudalla <kai.hudalla@bosch-si.com>
  • Loading branch information
Kai Hudalla committed Apr 6, 2018
1 parent 0ada2d7 commit daa375b
Show file tree
Hide file tree
Showing 13 changed files with 238 additions and 47 deletions.
20 changes: 14 additions & 6 deletions core/src/test/java/org/eclipse/hono/config/AbstractConfigTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2017 Red Hat Inc and others.
* Copyright (c) 2017, 2018 Red Hat Inc and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
Expand All @@ -14,25 +14,36 @@
import static org.hamcrest.core.IsInstanceOf.instanceOf;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

import io.vertx.core.net.KeyCertOptions;
import io.vertx.core.net.PemKeyCertOptions;
import io.vertx.core.net.PfxOptions;

/**
* Tests verifying behavior of {@link AbstractConfig}.
*
*/
public class AbstractConfigTest {

private static final String PREFIX_KEY_PATH = "target/certs/";
private AbstractConfig cfg;

private static final class TestConfig extends AbstractConfig {
/**
* Sets up the fixture.
*/
@Before
public void setup() {
cfg = new AbstractConfig() {
};
}

/**
* Test a valid PFX configuration.
*/
@Test
public void testPfxConfig() {
final TestConfig cfg = new TestConfig();
cfg.setKeyStorePath(PREFIX_KEY_PATH + "honoKeyStore.p12");
cfg.setKeyStorePassword("honokeys");

Expand All @@ -47,7 +58,6 @@ public void testPfxConfig() {
*/
@Test
public void testPemConfig() {
final TestConfig cfg = new TestConfig();
cfg.setKeyPath(PREFIX_KEY_PATH + "hono-messaging-key.pem");
cfg.setCertPath(PREFIX_KEY_PATH + "hono-messaging-cert.pem");

Expand All @@ -62,7 +72,6 @@ public void testPemConfig() {
*/
@Test
public void testInvalidConfig1() {
final TestConfig cfg = new TestConfig();
cfg.setKeyPath(PREFIX_KEY_PATH + "hono-messaging-key.pem");
cfg.setCertPath(PREFIX_KEY_PATH + "hono-messaging-cert.pem");
cfg.setKeyFormat(FileFormat.PKCS12);
Expand All @@ -77,7 +86,6 @@ public void testInvalidConfig1() {
*/
@Test
public void testInvalidConfig2() {
final TestConfig cfg = new TestConfig();
cfg.setKeyStorePath(PREFIX_KEY_PATH + "honoKeyStore.p12");
cfg.setKeyStorePassword("honokeys");

Expand Down
21 changes: 18 additions & 3 deletions core/src/test/java/org/eclipse/hono/config/FileFormatTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2017 Red Hat Inc and others.
* Copyright (c) 2017, 2018 Red Hat Inc and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
Expand All @@ -11,13 +11,19 @@
*/
package org.eclipse.hono.config;

import static org.eclipse.hono.config.FileFormat.detect;
import static org.junit.Assert.assertEquals;

import org.junit.Test;

/**
* Tests verifying behavior of {@link FileFormat}.
*
*/
public class FileFormatTest {

/**
* Verifies that the PEM format is detected in all its variants.
*/
@Test
public void testPem() {
assertName(FileFormat.PEM, "/foo/bar/baz.pem");
Expand All @@ -28,6 +34,9 @@ public void testPem() {
assertName(FileFormat.PEM, "foo.pem");
}

/**
* Verifies that the PFX format is detected in all its variants.
*/
@Test
public void testPfx() {
assertName(FileFormat.PKCS12, "/foo/bar/baz.pfx");
Expand All @@ -38,13 +47,19 @@ public void testPfx() {
assertName(FileFormat.PKCS12, "foo.pfx");
}

/**
* Verifies that the P12 format is detected in all its variants.
*/
@Test
public void testP12() {
assertName(FileFormat.PKCS12, "/foo/bar/baz.p12");
assertName(FileFormat.PKCS12, "/foo/bar/baz.P12");
assertName(FileFormat.PKCS12, "foo.p12");
}

/**
* Verifies that the JKS format is detected in all its variants.
*/
@Test
public void testJks() {
assertName(FileFormat.JKS, "/foo/bar/baz.jks");
Expand All @@ -56,7 +71,7 @@ public void testJks() {
}

private void assertName(final FileFormat format, final String name) {
FileFormat result = detect(name);
final FileFormat result = FileFormat.detect(name);
assertEquals(format, result);
}
}
34 changes: 32 additions & 2 deletions core/src/test/java/org/eclipse/hono/config/KeyLoaderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,33 @@ public class KeyLoaderTest {
private static final String PREFIX_KEY_PATH = "target/certs/";
private static final String PREFIX_KEY_PATH_2 = "src/test/resources/testpem/";

Vertx vertx = Vertx.vertx();
final Vertx vertx = Vertx.vertx();

/**
* Verifies that the loader loads an existing P12 key store.
*/
@Test
public void testLoaderSucceedsForExistingKeyStore() {

KeyLoader loader = KeyLoader.fromKeyStore(vertx, PREFIX_KEY_PATH + "honoKeyStore.p12",
final KeyLoader loader = KeyLoader.fromKeyStore(vertx, PREFIX_KEY_PATH + "honoKeyStore.p12",
"honokeys".toCharArray());
assertNotNull(loader.getPrivateKey());
assertNotNull(loader.getPublicKey());
}

/**
* Verifies that the loader fails to load a non-existing key store.
*/
@Test(expected = IllegalArgumentException.class)
public void testLoaderFailsForNonExistingKeyStore() {

KeyLoader.fromKeyStore(vertx, "non-existing.p12", "secret".toCharArray());
}

/**
* Verifies that the loader loads a private key and certificate from
* existing PEM files.
*/
@Test
public void testLoaderSucceedsForExistingKeyAndCertFiles() {

Expand All @@ -53,6 +63,10 @@ public void testLoaderSucceedsForExistingKeyAndCertFiles() {
assertNotNull(loader.getPublicKey());
}

/**
* Verifies that the loader loads a private key from
* an existing PEM file.
*/
@Test
public void testLoaderSucceedsForExistingKeyFile() {

Expand All @@ -61,6 +75,10 @@ public void testLoaderSucceedsForExistingKeyFile() {
assertNull(loader.getPublicKey());
}

/**
* Verifies that the loader loads a certificate from
* an existing PEM file.
*/
@Test
public void testLoaderSucceedsForExistingCertFile() {

Expand All @@ -69,18 +87,30 @@ public void testLoaderSucceedsForExistingCertFile() {
assertNotNull(loader.getPublicKey());
}

/**
* Verifies that the loader fails to load a private key from
* a non-existing PEM file.
*/
@Test(expected = IllegalArgumentException.class)
public void testLoaderFailsForNonExistingKeyFile() {

KeyLoader.fromFiles(vertx, "non-existing-key.pem", PREFIX_KEY_PATH + "hono-messaging-cert.pem");
}

/**
* Verifies that the loader fails to load a certificate from
* a non-existing PEM file.
*/
@Test(expected = IllegalArgumentException.class)
public void testLoaderFailsForNonExistingCertFile() {

KeyLoader.fromFiles(vertx, PREFIX_KEY_PATH + "hono-messaging-key.pem", "non-existing-cert.pem");
}

/**
* Verifies that the loader loads a private key from
* an existing pkcs1 PEM file.
*/
@Test
public void testLoaderPkcs1PrivateKey() {
KeyLoader.fromFiles(vertx, PREFIX_KEY_PATH_2 + "pkcs1-private-key.pem", null);
Expand Down
10 changes: 5 additions & 5 deletions core/src/test/java/org/eclipse/hono/config/PemReaderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public void testEmpty() throws IOException {
}

/**
* Bogus payload in the middle
* Bogus payload in the middle.
*
* @throws IOException if the test fails.
*/
Expand All @@ -112,7 +112,7 @@ public void testError1() throws IOException {
}

/**
* Missing END statement
* Missing END statement.
*
* @throws IOException if the test fails.
*/
Expand All @@ -122,7 +122,7 @@ public void testError2() throws IOException {
}

/**
* Only end END statement
* Only end END statement.
*
* @throws IOException if the test fails.
*/
Expand All @@ -132,7 +132,7 @@ public void testError3() throws IOException {
}

/**
* Duplicate BEGIN
* Duplicate BEGIN.
*
* @throws IOException if the test fails.
*/
Expand All @@ -142,7 +142,7 @@ public void testError4() throws IOException {
}

/**
* Missing BEGIN
* Missing BEGIN.
*
* @throws IOException if the test fails.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2017 Bosch Software Innovations GmbH.
* Copyright (c) 2017, 2018 Bosch Software Innovations GmbH.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
Expand All @@ -12,7 +12,6 @@

package org.eclipse.hono.util;

import static org.eclipse.hono.util.PortConfigurationHelper.isValidPort;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

Expand All @@ -25,14 +24,17 @@
*/
public class PortConfigurationHelperTest {

/**
* Verifies that the helper rejects ports &lt; 0 or &gt; 65535.
*/
@Test
public void testIsValidPort() throws Exception {
public void testIsValidPort() {

assertTrue("Lower inclusive bound", isValidPort(0));
assertTrue("Upper inclusive bound", isValidPort(65535));
assertTrue("Lower inclusive bound", PortConfigurationHelper.isValidPort(0));
assertTrue("Upper inclusive bound", PortConfigurationHelper.isValidPort(65535));

assertFalse("Lower exclusive bound", isValidPort(-1));
assertFalse("Upper exclusive bound", isValidPort(65536));
assertFalse("Lower exclusive bound", PortConfigurationHelper.isValidPort(-1));
assertFalse("Upper exclusive bound", PortConfigurationHelper.isValidPort(65536));
}

}
30 changes: 16 additions & 14 deletions core/src/test/java/org/eclipse/hono/util/StringsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,19 @@

package org.eclipse.hono.util;

import static org.eclipse.hono.util.Strings.isNullOrEmpty;
import static org.junit.Assert.*;

import org.junit.Assert;
import org.junit.Test;

/**
* Unit tests for {@link Strings}
* Unit tests for {@link Strings}.
*
*/
public class StringsTest {

/**
* Helper class.
*/
private static class Mock {

private String value;
Expand All @@ -39,43 +41,43 @@ public String toString() {
}

/**
* Test primary null value
* Test primary null value.
*/
@Test
public void testNull() {
Assert.assertTrue(isNullOrEmpty(null));
assertTrue(Strings.isNullOrEmpty(null));
}

/**
* Test empty string
* Test empty string.
*/
@Test
public void testEmpty() {
Assert.assertTrue(isNullOrEmpty(""));
assertTrue(Strings.isNullOrEmpty(""));
}

/**
* Test non-empty string
* Test non-empty string.
*/
@Test
public void testNonEmpty() {
Assert.assertFalse(isNullOrEmpty("foo"));
assertFalse(Strings.isNullOrEmpty("foo"));
}

/**
* Test object returning non-empty string in toString()
* Test object returning non-empty string in toString().
*/
@Test
public void testNonEmptyNonString() {
Assert.assertFalse(isNullOrEmpty(new Mock("foo")));
assertFalse(Strings.isNullOrEmpty(new Mock("foo")));
}

/**
* Test object returning empty string in toString()
* Test object returning empty string in toString().
*/
@Test
public void testEmptyNonString() {
Assert.assertTrue(isNullOrEmpty(new Mock("")));
assertTrue(Strings.isNullOrEmpty(new Mock("")));
}

/**
Expand All @@ -85,6 +87,6 @@ public void testEmptyNonString() {
*/
@Test
public void testNullNonString() {
Assert.assertTrue(isNullOrEmpty(new Mock(null)));
assertTrue(Strings.isNullOrEmpty(new Mock(null)));
}
}
Loading

0 comments on commit daa375b

Please sign in to comment.