Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
rest-api: Retrieval of all URLs is now working.
Browse files Browse the repository at this point in the history
  • Loading branch information
jkremser committed Dec 11, 2015
1 parent 42dcd17 commit 4930b94
Show file tree
Hide file tree
Showing 14 changed files with 84 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,32 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.hawkular.rest.filters;

import org.junit.Assert;
import org.junit.Test;
package org.hawkular.integration.test

import org.junit.AfterClass
import org.junit.Assert
import org.junit.Test

import static org.junit.Assert.assertEquals
import static org.junit.Assert.assertTrue

class RestApiTest extends AbstractTestBase {

private static List<String> pathsToDelete = new ArrayList();

/**
*/
public class ParamPropertiesTest {
@Test
public void testParser() {
Assert.assertTrue(true);
public void testScenario() throws Exception {
assertTrue(!false);
}

@AfterClass
static void cleanUp() {

}

private void assertResponseOk(int responseCode) {
assertTrue("Response code should be 2xx or 304 but was "+ responseCode,
(responseCode >= 200 && responseCode < 300) || responseCode == 304)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ public void getUrl(AsyncResponse asyncResponse, String id, String authToken) {
observer.subscribe((commandResponse) -> asyncResponse.resume(commandResponse));
}

@Override
public void getAll(AsyncResponse asyncResponse, String authToken) {
getUrl(asyncResponse, null, authToken);
}

@Override
public void createUrl(AsyncResponse asyncResponse, URL url, String authToken) {
String tenantId = getTenantId();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@
public interface RestURL {

@GET
@Path("/{urlId}")
@ApiOperation("Retrieves the tenant of the currently logged in persona")
@Path("{urlId}")
@ApiOperation("Retrieves the URL of the currently logged in persona")
@ApiResponses({
@ApiResponse(code = 200, message = "OK"),
@ApiResponse(code = 401, message = "Unauthorized access"),
Expand All @@ -62,9 +62,19 @@ public interface RestURL {
@PathParam("urlId") String id,
@HeaderParam("Authorization") String authToken);

@GET
@ApiOperation("Retrieves all URLs of the currently logged in persona")
@ApiResponses({
@ApiResponse(code = 200, message = "OK"),
@ApiResponse(code = 401, message = "Unauthorized access"),
@ApiResponse(code = 404, message = "Tenant doesn't exist", response = ApiError.class),
@ApiResponse(code = 500, message = "Server error", response = ApiError.class)
}) void getAll(@Suspended AsyncResponse asyncResponse,
@HeaderParam("Authorization") String authToken);

@POST
@Path("/")
@ApiOperation("Retrieves the tenant of the currently logged in persona")
@ApiOperation("Creates the URL of the currently logged in persona")
@ApiResponses({
@ApiResponse(code = 200, message = "OK"),
@ApiResponse(code = 401, message = "Unauthorized access"),
Expand All @@ -76,7 +86,7 @@ public interface RestURL {

@PUT
@Path("/")
@ApiOperation("Updates properties of the current tenant")
@ApiOperation("Updates properties of the URL")
@ApiResponses({
@ApiResponse(code = 204, message = "OK"),
@ApiResponse(code = 400, message = "Invalid input data", response = ApiError.class),
Expand All @@ -90,7 +100,7 @@ public interface RestURL {

@DELETE
@Path("/")
@ApiOperation("Deletes the tenant and all its data. Be careful!")
@ApiOperation("Deletes the URL and all its data")
@ApiResponses({
@ApiResponse(code = 204, message = "OK"),
@ApiResponse(code = 401, message = "Unauthorized access"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@ protected AbstractHttpCommand(HystrixCommandGroupKey group) {
super(group);
}

protected List<ImmutablePair<Class, Consumer>> getSetters() {
throw new UnsupportedOperationException("This method should be overriden in a sub-class");
}
protected abstract List<ImmutablePair<Class, Consumer>> getSetters();

protected void initialize(InjectionPoint ip) {
boolean annotationFound = false;
Expand All @@ -58,6 +56,9 @@ protected void initialize(InjectionPoint ip) {
}
int index = 0;
for (ImmutablePair<Class, Consumer> setter : setters) {
if (values[index] == null) {
setter.getRight().accept(null);
}
if (setter.getLeft().equals(String.class)) {
setter.getRight().accept(values[index]);
} else if (setter.getLeft().equals(int.class) || setter.getLeft().equals(Integer.class)) {
Expand All @@ -78,4 +79,8 @@ protected void initialize(InjectionPoint ip) {
throw new IllegalStateException("No @WithValues on InjectionPoint");
}
}

protected String nullOrStr(Object input) {
return input == null ? null : String.valueOf(input);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,9 @@ public class CreateUrlCommand extends AbstractHttpCommand<String> {
@Override
protected List<ImmutablePair<Class, Consumer>> getSetters() {
return Arrays.asList(
new ImmutablePair<>(String.class, (x) -> CreateUrlCommand.this.url = makeUrlWithProtocol(String
.valueOf(x))),
new ImmutablePair<>(String.class, (x) -> CreateUrlCommand.this.authToken = String.valueOf(x)),
new ImmutablePair<>(String.class, (x) -> CreateUrlCommand.this.persona = String.valueOf(x))
new ImmutablePair<>(String.class, (x) -> CreateUrlCommand.this.url = makeUrlWithProtocol(nullOrStr(x))),
new ImmutablePair<>(String.class, (x) -> CreateUrlCommand.this.authToken = nullOrStr(x)),
new ImmutablePair<>(String.class, (x) -> CreateUrlCommand.this.persona = nullOrStr(x))
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ public class DeleteUrlCommand extends AbstractHttpCommand<String> {
@Override
protected List<ImmutablePair<Class, Consumer>> getSetters() {
return Arrays.asList(
new ImmutablePair<>(String.class, (x) -> DeleteUrlCommand.this.urlId = String.valueOf(x)),
new ImmutablePair<>(String.class, (x) -> DeleteUrlCommand.this.authToken = String.valueOf(x)),
new ImmutablePair<>(String.class, (x) -> DeleteUrlCommand.this.persona = String.valueOf(x))
new ImmutablePair<>(String.class, (x) -> DeleteUrlCommand.this.urlId = nullOrStr(x)),
new ImmutablePair<>(String.class, (x) -> DeleteUrlCommand.this.authToken = nullOrStr(x)),
new ImmutablePair<>(String.class, (x) -> DeleteUrlCommand.this.persona = nullOrStr(x))
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ public class GetUrlCommand extends AbstractHttpCommand<String> {
@Override
protected List<ImmutablePair<Class, Consumer>> getSetters() {
return Arrays.asList(
new ImmutablePair<>(String.class, (x) -> GetUrlCommand.this.id = String.valueOf(x)),
new ImmutablePair<>(String.class, (x) -> GetUrlCommand.this.authToken = String.valueOf(x)),
new ImmutablePair<>(String.class, (x) -> GetUrlCommand.this.persona = String.valueOf(x))
new ImmutablePair<>(String.class, (x) -> GetUrlCommand.this.id = nullOrStr(x)),
new ImmutablePair<>(String.class, (x) -> GetUrlCommand.this.authToken = nullOrStr(x)),
new ImmutablePair<>(String.class, (x) -> GetUrlCommand.this.persona = nullOrStr(x))
);
}

Expand All @@ -74,7 +74,7 @@ private GetUrlCommand(InjectionPoint ip) {
@Override
public void call(Subscriber<? super String> observer) {
try {
String url = id == null && id.trim().isEmpty() ?
String url = id == null || id.trim().isEmpty() ?
config.URL_INVENTORY + "/resourceTypes/URL/resources" :
config.URL_INVENTORY + "/test/resources/" + id;
String response = client.get(authToken, persona, url);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,10 @@ public class UpdateUrlCommand extends CreateUrlCommand {
@Override
protected List<ImmutablePair<Class, Consumer>> getSetters() {
return Arrays.asList(
new ImmutablePair<>(String.class, (x) -> UpdateUrlCommand.this.urlId = String.valueOf(x)),
new ImmutablePair<>(String.class, (x) -> UpdateUrlCommand.this.url = makeUrlWithProtocol(String
.valueOf(x))),
new ImmutablePair<>(String.class, (x) -> UpdateUrlCommand.this.authToken = String.valueOf(x)),
new ImmutablePair<>(String.class, (x) -> UpdateUrlCommand.this.persona = String.valueOf(x))
new ImmutablePair<>(String.class, (x) -> UpdateUrlCommand.this.urlId = nullOrStr(x)),
new ImmutablePair<>(String.class, (x) -> UpdateUrlCommand.this.url = makeUrlWithProtocol(nullOrStr(x))),
new ImmutablePair<>(String.class, (x) -> UpdateUrlCommand.this.authToken = nullOrStr(x)),
new ImmutablePair<>(String.class, (x) -> UpdateUrlCommand.this.persona = nullOrStr(x))
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ public class CreateMetricCommand extends AbstractHttpCommand<String> {
protected List<ImmutablePair<Class, Consumer>> getSetters() {
final CreateMetricCommand self = CreateMetricCommand.this;
return Arrays.asList(
new ImmutablePair<>(String.class, (x) -> self.authToken = String.valueOf(x)),
new ImmutablePair<>(String.class, (x) -> self.persona = String.valueOf(x))
new ImmutablePair<>(String.class, (x) -> self.authToken = nullOrStr(x)),
new ImmutablePair<>(String.class, (x) -> self.persona = nullOrStr(x))
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ public class CreateResourceCommand extends AbstractHttpCommand<String> {
protected List<ImmutablePair<Class, Consumer>> getSetters() {
final CreateResourceCommand self = CreateResourceCommand.this;
return Arrays.asList(
new ImmutablePair<>(String.class, (x) -> self.authToken = String.valueOf(x)),
new ImmutablePair<>(String.class, (x) -> self.persona = String.valueOf(x))
new ImmutablePair<>(String.class, (x) -> self.authToken = nullOrStr(x)),
new ImmutablePair<>(String.class, (x) -> self.persona = nullOrStr(x))
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ public class DeleteMetricCommand extends AbstractHttpCommand<String> {
protected List<ImmutablePair<Class, Consumer>> getSetters() {
final DeleteMetricCommand self = DeleteMetricCommand.this;
return Arrays.asList(
new ImmutablePair<>(String.class, (x) -> self.metricId = String.valueOf(x)),
new ImmutablePair<>(String.class, (x) -> self.authToken = String.valueOf(x)),
new ImmutablePair<>(String.class, (x) -> self.persona = String.valueOf(x))
new ImmutablePair<>(String.class, (x) -> self.metricId = nullOrStr(x)),
new ImmutablePair<>(String.class, (x) -> self.authToken = nullOrStr(x)),
new ImmutablePair<>(String.class, (x) -> self.persona = nullOrStr(x))
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ public class DeleteResourceCommand extends AbstractHttpCommand<String> {
protected List<ImmutablePair<Class, Consumer>> getSetters() {
final DeleteResourceCommand self = DeleteResourceCommand.this;
return Arrays.asList(
new ImmutablePair<>(String.class, (x) -> self.resourceId = String.valueOf(x)),
new ImmutablePair<>(String.class, (x) -> self.authToken = String.valueOf(x)),
new ImmutablePair<>(String.class, (x) -> self.persona = String.valueOf(x))
new ImmutablePair<>(String.class, (x) -> self.resourceId = nullOrStr(x)),
new ImmutablePair<>(String.class, (x) -> self.authToken = nullOrStr(x)),
new ImmutablePair<>(String.class, (x) -> self.persona = nullOrStr(x))
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ public class UpdateResourceCommand extends AbstractHttpCommand<String> {
protected List<ImmutablePair<Class, Consumer>> getSetters() {
final UpdateResourceCommand self = UpdateResourceCommand.this;
return Arrays.asList(
new ImmutablePair<>(String.class, (x) -> self.authToken = String.valueOf(x)),
new ImmutablePair<>(String.class, (x) -> self.persona = String.valueOf(x))
new ImmutablePair<>(String.class, (x) -> self.authToken = nullOrStr(x)),
new ImmutablePair<>(String.class, (x) -> self.persona = nullOrStr(x))
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ public class CreateMetricCommand extends AbstractHttpCommand<String> {
protected List<ImmutablePair<Class, Consumer>> getSetters() {
final CreateMetricCommand self = CreateMetricCommand.this;
return Arrays.asList(
new ImmutablePair<>(String.class, (x) -> self.authToken = String.valueOf(x)),
new ImmutablePair<>(String.class, (x) -> self.persona = String.valueOf(x))
new ImmutablePair<>(String.class, (x) -> self.authToken = nullOrStr(x)),
new ImmutablePair<>(String.class, (x) -> self.persona = nullOrStr(x))
);
}

Expand All @@ -71,7 +71,7 @@ protected List<ImmutablePair<Class, Consumer>> getSetters() {

@Inject
private CreateMetricCommand(InjectionPoint ip) {
super(HystrixCommandGroupKey.Factory.asKey("inventory-metric"));
super(HystrixCommandGroupKey.Factory.asKey("metric-metric"));
initialize(ip);
}

Expand All @@ -81,11 +81,12 @@ private CreateMetricCommand(InjectionPoint ip) {
@Override
public void call(Subscriber<? super String> observer) {
try {
// todo: finish
String url;
if (resourcePath != null) {
url = config.URL_INVENTORY + "/test/resources/" + resourcePath + "/metrics";
url = config.URL_METRICS + "/test/resources/" + resourcePath + "/metrics";
} else {
url = config.URL_INVENTORY + "/test/metrics";
url = config.URL_METRICS + "/test/metrics";
}
String response = client.post(authToken, persona, url, mapper.writeValueAsString(metric));

Expand Down

0 comments on commit 4930b94

Please sign in to comment.