private void assertSendContents(String contents, PluginType type, String pluginName, String resourceType, String resourceName) throws Exception { assertSendContents(contents, new ResourceType(type, pluginName, resourceType), resourceName); }
@Test public void testStageRecallOnNonexistentReturns404() throws Exception { ResourceType cookbooks = new ResourceType(PluginType.AUTOMATOR, "chef-solo", "cookbooks"); ResourceType keys = new ResourceType(PluginType.PROVIDER, "joyent", "keys"); assertSendContents("hadoop contents 1", cookbooks, "hadoop"); assertSendContents("dev keys 1", keys, "dev"); List<String> paths = ImmutableList.of( getVersionedPath(cookbooks, "hadoop", 2) + "/stage", getVersionedPath(cookbooks, "hadoop", 2) + "/recall", getVersionedPath(keys, "dev", 2) + "/stage", getVersionedPath(keys, "dev", 2) + "/recall" ); for (String path : paths) { assertResponseStatus(doPostExternalAPI(path, "", ADMIN_HEADERS), HttpResponseStatus.NOT_FOUND); } }
private void testGetAndDelete(ResourceType type) throws Exception { String contents = "some contents"; ResourceMeta meta1 = new ResourceMeta("name1", 1, ResourceStatus.INACTIVE); ResourceMeta meta2 = new ResourceMeta("name1", 2, ResourceStatus.INACTIVE); ResourceMeta meta3 = new ResourceMeta("name2", 1, ResourceStatus.INACTIVE); ResourceMeta meta4 = new ResourceMeta("name3", 1, ResourceStatus.INACTIVE); assertSendContents(contents, type, meta1.getName()); assertSendContents(contents, type, meta2.getName()); assertSendContents(contents, type, meta3.getName()); assertSendContents(contents, type, meta4.getName()); HttpResponse response = doGetExternalAPI(getTypePath(type), ADMIN_HEADERS); assertResponseStatus(response, HttpResponseStatus.OK); Assert.assertEquals( ImmutableMap.<String, Set<ResourceMeta>>of( "name1", ImmutableSet.<ResourceMeta>of(meta1, meta2), "name2", ImmutableSet.<ResourceMeta>of(meta3), "name3", ImmutableSet.<ResourceMeta>of(meta4)), bodyToMetaMap(response) ); // delete one assertResponseStatus(doDeleteExternalAPI(getVersionedPath(type, meta3), ADMIN_HEADERS), HttpResponseStatus.OK); response = doGetExternalAPI(getTypePath(type), ADMIN_HEADERS); assertResponseStatus(response, HttpResponseStatus.OK); Assert.assertEquals( ImmutableMap.<String, Set<ResourceMeta>>of( "name1", ImmutableSet.<ResourceMeta>of(meta1, meta2), "name3", ImmutableSet.<ResourceMeta>of(meta4)), bodyToMetaMap(response) ); }
private void testPutAndGet(PluginType type, String pluginName, String resourceType) throws Exception { String contents = RandomStringUtils.randomAlphanumeric(8 * Constants.PLUGIN_RESOURCE_CHUNK_SIZE); ResourceType pluginResourceType = new ResourceType(type, pluginName, resourceType); ResourceMeta meta = new ResourceMeta("hello", 1, ResourceStatus.INACTIVE); assertSendContents(contents, type, pluginName, resourceType, "hello"); // get metadata HttpResponse response = doGetExternalAPI(getNamePath(pluginResourceType, meta.getName()), ADMIN_HEADERS); assertResponseStatus(response, HttpResponseStatus.OK); Assert.assertEquals(ImmutableSet.of(meta), bodyToMetaSet(response)); // get actual contents String typeStr = type.name().toLowerCase() + "types"; String path = Joiner.on('/').join( "/tenants", ADMIN_ACCOUNT.getTenantId(), typeStr, pluginName, resourceType, meta.getName(), "versions", meta.getVersion() ); response = doGetInternalAPI(path); assertResponseStatus(response, HttpResponseStatus.OK); Assert.assertEquals(contents, bodyToString(response)); }
assertSendContents("hadoop contents 1", cookbooks, "hadoop"); assertSendContents("hadoop contents 2", cookbooks, "hadoop"); assertSendContents("hadoop contents 3", cookbooks, "hadoop"); assertSendContents("mysql contents 1", cookbooks, "mysql"); assertSendContents("mysql contents 2", cookbooks, "mysql"); assertSendContents("dev keys 1", keys, "dev"); assertSendContents("dev keys 2", keys, "dev"); assertSendContents("research keys 1", keys, "research");
ResourceMeta meta1 = new ResourceMeta("name", 1, ResourceStatus.INACTIVE); ResourceMeta meta2 = new ResourceMeta("name", 2, ResourceStatus.INACTIVE); assertSendContents(contents, pluginResourceType, meta1.getName()); assertSendContents(contents, pluginResourceType, meta2.getName());