updated to fixed orbitz client
Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/81d36f3c Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/81d36f3c Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/81d36f3c Branch: refs/heads/master Commit: 81d36f3c18732eb15fe7b9157923cb68ff8f2fcc Parents: cc1e8a0 Author: Bernd Prager <be...@prager.ws> Authored: Thu May 26 08:51:32 2016 -0400 Committer: Claus Ibsen <davscl...@apache.org> Committed: Sat May 28 09:18:07 2016 +0200 ---------------------------------------------------------------------- .../camel/component/consul/ConsulRegistry.java | 4 +- .../component/consul/ConsulRegistryTest.java | 160 +++++++++++++++++-- parent/pom.xml | 4 +- 3 files changed, 150 insertions(+), 18 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/81d36f3c/components/camel-consul/src/main/java/org/apache/camel/component/consul/ConsulRegistry.java ---------------------------------------------------------------------- diff --git a/components/camel-consul/src/main/java/org/apache/camel/component/consul/ConsulRegistry.java b/components/camel-consul/src/main/java/org/apache/camel/component/consul/ConsulRegistry.java index 7f959b4..6a51308 100644 --- a/components/camel-consul/src/main/java/org/apache/camel/component/consul/ConsulRegistry.java +++ b/components/camel-consul/src/main/java/org/apache/camel/component/consul/ConsulRegistry.java @@ -26,8 +26,8 @@ import java.util.UUID; import org.apache.camel.NoSuchBeanException; import org.apache.camel.spi.Registry; -import org.apache.commons.lang.SerializationUtils; import org.apache.commons.codec.binary.Base64; +import org.apache.commons.lang.SerializationUtils; import com.google.common.base.Optional; import com.google.common.net.HostAndPort; @@ -47,7 +47,7 @@ import com.orbitz.consul.model.session.SessionCreatedResponse; * */ public class ConsulRegistry implements Registry { - + private String hostname = "localhost"; private int port = 8500; private Consul consul; http://git-wip-us.apache.org/repos/asf/camel/blob/81d36f3c/components/camel-consul/src/test/java/org/apache/camel/component/consul/ConsulRegistryTest.java ---------------------------------------------------------------------- diff --git a/components/camel-consul/src/test/java/org/apache/camel/component/consul/ConsulRegistryTest.java b/components/camel-consul/src/test/java/org/apache/camel/component/consul/ConsulRegistryTest.java index 03be60e..9abc248 100644 --- a/components/camel-consul/src/test/java/org/apache/camel/component/consul/ConsulRegistryTest.java +++ b/components/camel-consul/src/test/java/org/apache/camel/component/consul/ConsulRegistryTest.java @@ -1,12 +1,11 @@ /** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at + * Copyright (C) 2015 Bernd Prager <http://prager.ws> * - * http://www.apache.org/licenses/LICENSE-2.0 + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,16 +15,149 @@ */ package org.apache.camel.component.consul; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; + +import java.io.Serializable; import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; +import org.apache.camel.NoSuchBeanException; +import org.apache.log4j.Logger; import org.junit.BeforeClass; +import org.junit.Test; + +/** + * + * @author Bernd Prager Unit test for Camel Registry implementation for Consul + */ +public class ConsulRegistryTest implements Serializable { + + private static final long serialVersionUID = -3482971969351609265L; + private static ConsulRegistry registry; + private static final Logger LOGGER = Logger.getLogger(ConsulRegistryTest.class); + + public class ConsulTestClass implements Serializable { + private static final long serialVersionUID = -4815945688487114891L; + + public String hello(String name) { + return "Hello " + name; + } + } + + @BeforeClass + public static void setUp() { + registry = new ConsulRegistry.Builder("localhost").build(); + } + + @Test + public void storeString() { + registry.put("stringTestKey", "stringValue"); + String result = (String) registry.lookupByName("stringTestKey"); + registry.remove("stringTestKey"); + assertNotNull(result); + assertEquals("stringValue", result); + } + + @Test + public void overrideExistingKey() { + registry.put("uniqueKey", "stringValueOne"); + registry.put("uniqueKey", "stringValueTwo"); + String result = (String) registry.lookupByName("uniqueKey"); + registry.remove("uniqueKey"); + assertNotNull(result); + assertEquals("stringValueTwo", result); + } + + @Test + public void checkLookupByName() { + registry.put("namedKey", "namedValue"); + String result = (String) registry.lookupByName("namedKey"); + registry.remove("namedKey"); + assertNotNull(result); + assertEquals("namedValue", result); + } + + @Test + public void checkFailedLookupByName() { + registry.put("namedKey", "namedValue"); + registry.remove("namedKey"); + String result = (String) registry.lookupByName("namedKey"); + assertNull(result); + } + + @Test + public void checkLookupByNameAndType() { + ConsulTestClass consulTestClass = new ConsulTestClass(); + registry.put("testClass", consulTestClass); + ConsulTestClass consulTestClassClone = registry.lookupByNameAndType("testClass", consulTestClass.getClass()); + registry.remove("testClass"); + assertNotNull(consulTestClassClone); + assertEquals(consulTestClass.getClass(), consulTestClassClone.getClass()); + } + + @Test + public void checkFailedLookupByNameAndType() { + ConsulTestClass consulTestClass = new ConsulTestClass(); + registry.put("testClass", consulTestClass); + registry.remove("testClass"); + ConsulTestClass consulTestClassClone = registry.lookupByNameAndType("testClass", consulTestClass.getClass()); + assertNull(consulTestClassClone); + } + + @Test + public void checkFindByTypeWithName() { + ConsulTestClass consulTestClassOne = new ConsulTestClass(); + ConsulTestClass consulTestClassTwo = new ConsulTestClass(); + registry.put("testClassOne", consulTestClassOne); + registry.put("testClassTwo", consulTestClassTwo); + Map<String, ? extends ConsulTestClass> consulTestClassMap = registry + .findByTypeWithName(consulTestClassOne.getClass()); + registry.remove("testClassOne"); + registry.remove("testClassTwo"); + HashMap<String, ConsulTestClass> emptyHashMap = new HashMap<String, ConsulTestClass>(); + assertNotNull(consulTestClassMap); + assertEquals(consulTestClassMap.getClass(), emptyHashMap.getClass()); + assertEquals(2, consulTestClassMap.size()); + } + + public void checkFailedFindByTypeWithName() { + + } + + @Test + public void storeObject() { + ConsulTestClass testObject = new ConsulTestClass(); + registry.put("objectTestClass", testObject); + ConsulTestClass clone = (ConsulTestClass) registry.lookupByName("objectTestClass"); + assertEquals(clone.hello("World"), "Hello World"); + registry.remove("objectTestClass"); + } + + @Test + public void findByType() { + ConsulTestClass classOne = new ConsulTestClass(); + registry.put("classOne", classOne); + ConsulTestClass classTwo = new ConsulTestClass(); + registry.put("classTwo", classTwo); + Set<? extends ConsulTestClass> results = registry.findByType(classOne.getClass()); + assertNotNull(results); + HashSet<ConsulTestClass> hashSet = new HashSet<ConsulTestClass>(); + registry.remove("classOne"); + registry.remove("classTwo"); + assertEquals(results.getClass(), hashSet.getClass()); + assertEquals(2, results.size()); + } + + public void notFindByType() { -public class ConsulRegistryTest extends ConsulTestSupport { - - static HashMap<String, String> mockConsul; - - @BeforeClass public static void prepHashMap() { - mockConsul = new HashMap<String, String>(); - } + } + @Test(expected = NoSuchBeanException.class) + public void deleteNonExisting() { + registry.remove("nonExisting"); + } } http://git-wip-us.apache.org/repos/asf/camel/blob/81d36f3c/parent/pom.xml ---------------------------------------------------------------------- diff --git a/parent/pom.xml b/parent/pom.xml index 0535014..eca9f75 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -131,8 +131,8 @@ <commons-pool2-version>2.4.2</commons-pool2-version> <commons-vfs2-version>2.0</commons-vfs2-version> <compress-lzf-version>1.0.3</compress-lzf-version> - <consul-client-version>0.12.0</consul-client-version> - <consul-client-bundle-version>0.12.0_1</consul-client-bundle-version> + <consul-client-version>0.12.2</consul-client-version> + <consul-client-bundle-version>0.12.2</consul-client-bundle-version> <cobertura-maven-plugin-version>2.7</cobertura-maven-plugin-version> <cxf-version>3.1.6</cxf-version> <cxf-version-range>[3.0,4.0)</cxf-version-range>