Commit 3aea2301 by Mike Liu Committed by Johannes Edmeier

Expose registered id in ApplicationRegistrator

closes #404
parent 94aec760
...@@ -111,6 +111,16 @@ public class ApplicationRegistrator { ...@@ -111,6 +111,16 @@ public class ApplicationRegistrator {
} }
} }
} }
/**
* Returns the id of this client as given by the admin server.
* Returns null if the client has not registered against the admin server yet.
*
* @return
*/
public String getRegisteredId() {
return registeredId.get();
}
protected Application createApplication() { protected Application createApplication() {
return applicationFactory.createApplication(); return applicationFactory.createApplication();
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
*/ */
package de.codecentric.boot.admin.registration; package de.codecentric.boot.admin.registration;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.eq; import static org.mockito.Matchers.eq;
...@@ -77,6 +78,7 @@ public class ApplicationRegistratorTest { ...@@ -77,6 +78,7 @@ public class ApplicationRegistratorTest {
HttpStatus.CREATED)); HttpStatus.CREATED));
assertTrue(registrator.register()); assertTrue(registrator.register());
assertEquals("-id-", registrator.getRegisteredId());
verify(restTemplate) verify(restTemplate)
.postForEntity("http://sba:8080/api/applications", .postForEntity("http://sba:8080/api/applications",
new HttpEntity<>(Application.create("AppName") new HttpEntity<>(Application.create("AppName")
...@@ -92,6 +94,7 @@ public class ApplicationRegistratorTest { ...@@ -92,6 +94,7 @@ public class ApplicationRegistratorTest {
eq(Application.class))).thenThrow(new RestClientException("Error")); eq(Application.class))).thenThrow(new RestClientException("Error"));
assertFalse(registrator.register()); assertFalse(registrator.register());
assertEquals(null, registrator.getRegisteredId());
} }
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
...@@ -104,6 +107,7 @@ public class ApplicationRegistratorTest { ...@@ -104,6 +107,7 @@ public class ApplicationRegistratorTest {
HttpStatus.CREATED)); HttpStatus.CREATED));
assertTrue(registrator.register()); assertTrue(registrator.register());
assertEquals("-id-", registrator.getRegisteredId());
} }
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
...@@ -113,7 +117,9 @@ public class ApplicationRegistratorTest { ...@@ -113,7 +117,9 @@ public class ApplicationRegistratorTest {
.thenReturn(new ResponseEntity<Map>(Collections.singletonMap("id", "-id-"), .thenReturn(new ResponseEntity<Map>(Collections.singletonMap("id", "-id-"),
HttpStatus.CREATED)); HttpStatus.CREATED));
registrator.register(); registrator.register();
assertEquals("-id-", registrator.getRegisteredId());
registrator.deregister(); registrator.deregister();
assertEquals(null, registrator.getRegisteredId());
verify(restTemplate).delete("http://sba:8080/api/applications/-id-"); verify(restTemplate).delete("http://sba:8080/api/applications/-id-");
} }
...@@ -128,6 +134,7 @@ public class ApplicationRegistratorTest { ...@@ -128,6 +134,7 @@ public class ApplicationRegistratorTest {
HttpStatus.CREATED)); HttpStatus.CREATED));
assertTrue(registrator.register()); assertTrue(registrator.register());
assertEquals("-id-", registrator.getRegisteredId());
verify(restTemplate) verify(restTemplate)
.postForEntity("http://sba:8080/api/applications", .postForEntity("http://sba:8080/api/applications",
...@@ -157,6 +164,7 @@ public class ApplicationRegistratorTest { ...@@ -157,6 +164,7 @@ public class ApplicationRegistratorTest {
.thenThrow(new RestClientException("Error")); .thenThrow(new RestClientException("Error"));
assertTrue(registrator.register()); assertTrue(registrator.register());
assertEquals("-id-", registrator.getRegisteredId());
verify(restTemplate) verify(restTemplate)
.postForEntity("http://sba:8080/api/applications", .postForEntity("http://sba:8080/api/applications",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment