summaryrefslogtreecommitdiffstats
path: root/configserver
diff options
context:
space:
mode:
authorHarald Musum <musum@verizonmedia.com>2020-05-20 08:47:56 +0200
committerHarald Musum <musum@verizonmedia.com>2020-05-20 08:47:56 +0200
commit5e15161b828b85476cc4be44d473386b89008a58 (patch)
treed47c575690b04dc4868637cfa5a15624113a6122 /configserver
parentb7f9eff3bff206122a39dcc436469a7be5c4f9a7 (diff)
Simplify test
Avoid doing lots of low-level stuff, just check that we get correct application id from request. The rest is tested in ApplicationRepositoryTest.createFromActiveSession
Diffstat (limited to 'configserver')
-rw-r--r--configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/SessionCreateHandler.java2
-rw-r--r--configserver/src/test/java/com/yahoo/vespa/config/server/ApplicationRepositoryTest.java2
-rw-r--r--configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/SessionCreateHandlerTest.java47
3 files changed, 10 insertions, 41 deletions
diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/SessionCreateHandler.java b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/SessionCreateHandler.java
index 286adbd256d..5aee711b379 100644
--- a/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/SessionCreateHandler.java
+++ b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/SessionCreateHandler.java
@@ -63,7 +63,7 @@ public class SessionCreateHandler extends SessionHandler {
return createResponse(request, tenantName, deployLog, sessionId);
}
- private static ApplicationId getFromApplicationId(HttpRequest request) {
+ static ApplicationId getFromApplicationId(HttpRequest request) {
String from = request.getProperty("from");
if (from == null || "".equals(from)) {
throw new BadRequestException("Parameter 'from' has illegal value '" + from + "'");
diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/ApplicationRepositoryTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/ApplicationRepositoryTest.java
index a95a02180ca..ae7d5a48955 100644
--- a/configserver/src/test/java/com/yahoo/vespa/config/server/ApplicationRepositoryTest.java
+++ b/configserver/src/test/java/com/yahoo/vespa/config/server/ApplicationRepositoryTest.java
@@ -355,7 +355,7 @@ public class ApplicationRepositoryTest {
}
@Test
- public void deletesApplicationRoles() throws IOException {
+ public void deletesApplicationRoles() {
var tenant = tenantRepository.getTenant(tenant1);
var applicationId = applicationId(tenant1);
var prepareParams = new PrepareParams.Builder().applicationId(applicationId)
diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/SessionCreateHandlerTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/SessionCreateHandlerTest.java
index 5ea2ce5266b..9a1c476117d 100644
--- a/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/SessionCreateHandlerTest.java
+++ b/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/SessionCreateHandlerTest.java
@@ -1,17 +1,14 @@
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.config.server.http.v2;
-import com.yahoo.config.model.application.provider.FilesApplicationPackage;
import com.yahoo.config.provision.ApplicationId;
import com.yahoo.config.provision.TenantName;
import com.yahoo.container.jdisc.HttpRequest;
import com.yahoo.container.jdisc.HttpResponse;
import com.yahoo.vespa.config.server.ApplicationRepository;
-import com.yahoo.vespa.config.server.MockReloadHandler;
import com.yahoo.vespa.config.server.TestComponentRegistry;
-import com.yahoo.vespa.config.server.application.OrchestratorMock;
-import com.yahoo.vespa.config.server.application.TenantApplications;
import com.yahoo.vespa.config.server.application.CompressedApplicationInputStreamTest;
+import com.yahoo.vespa.config.server.application.OrchestratorMock;
import com.yahoo.vespa.config.server.http.HandlerTest;
import com.yahoo.vespa.config.server.http.HttpErrorResponse;
import com.yahoo.vespa.config.server.http.SessionHandlerTest;
@@ -37,6 +34,7 @@ import static com.yahoo.jdisc.Response.Status.OK;
import static com.yahoo.jdisc.http.HttpRequest.Method.GET;
import static com.yahoo.jdisc.http.HttpRequest.Method.POST;
import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
@@ -57,7 +55,6 @@ public class SessionCreateHandlerTest extends SessionHandlerTest {
public File testApp = new File("src/test/apps/app");
private LocalSessionRepo localSessionRepo;
- private TenantApplications applicationRepo;
private TenantRepository tenantRepository;
private MockSessionFactory sessionFactory;
@@ -67,14 +64,12 @@ public class SessionCreateHandlerTest extends SessionHandlerTest {
@Before
public void setupRepo() {
- applicationRepo = TenantApplications.create(componentRegistry, new MockReloadHandler(), tenant);
localSessionRepo = new LocalSessionRepo(tenant, componentRegistry);
tenantRepository = new TenantRepository(componentRegistry, false);
sessionFactory = new MockSessionFactory();
TenantBuilder tenantBuilder = TenantBuilder.create(componentRegistry, tenant)
.withSessionFactory(sessionFactory)
- .withLocalSessionRepo(localSessionRepo)
- .withApplicationRepo(applicationRepo);
+ .withLocalSessionRepo(localSessionRepo);
tenantRepository.addTenant(tenantBuilder);
pathPrefix = "/application/v2/tenant/" + tenant + "/session/";
createdMessage = " for tenant '" + tenant + "' created.\"";
@@ -103,19 +98,6 @@ public class SessionCreateHandlerTest extends SessionHandlerTest {
HandlerTest.assertHttpStatusCodeErrorCodeAndMessage(response, BAD_REQUEST, HttpErrorResponse.errorCodes.BAD_REQUEST, "Request contains no Content-Type header");
}
- private void assertFromParameter(String expected, String from) throws IOException {
- HttpRequest request = post(Collections.singletonMap("from", from));
- sessionFactory.applicationPackage = testApp;
- HttpResponse response = createHandler().handle(request);
- assertNotNull(response);
- assertThat(response.getStatus(), is(OK));
- assertTrue(sessionFactory.createFromCalled);
- assertThat(SessionHandlerTest.getRenderedString(response),
- is("{\"log\":[]" + tenantMessage + ",\"session-id\":\"" + expected + "\",\"prepared\":\"http://" + hostname + ":" + port + pathPrefix +
- expected + "/prepared\",\"content\":\"http://" + hostname + ":" + port + pathPrefix +
- expected + "/content/\",\"message\":\"Session " + expected + createdMessage + "}"));
- }
-
private void assertIllegalFromParameter(String fromValue) throws IOException {
File outFile = CompressedApplicationInputStreamTest.createTarFile();
HttpRequest request = post(outFile, postHeaders, Collections.singletonMap("from", fromValue));
@@ -182,24 +164,11 @@ public class SessionCreateHandlerTest extends SessionHandlerTest {
@Test
public void require_that_application_urls_can_be_given_as_from_parameter() throws Exception {
- localSessionRepo.addSession(new SessionHandlerTest.MockSession(2, FilesApplicationPackage.fromFile(testApp)));
- ApplicationId fooId = new ApplicationId.Builder()
- .tenant(tenant)
- .applicationName("foo")
- .instanceName("quux")
- .build();
- applicationRepo.createApplication(fooId);
- applicationRepo.createPutTransaction(fooId, 2).commit();
- assertFromParameter("3", "http://myhost:40555/application/v2/tenant/" + tenant + "/application/foo/environment/test/region/baz/instance/quux");
- localSessionRepo.addSession(new SessionHandlerTest.MockSession(5, FilesApplicationPackage.fromFile(testApp)));
- ApplicationId bioId = new ApplicationId.Builder()
- .tenant(tenant)
- .applicationName("foobio")
- .instanceName("quux")
- .build();
- applicationRepo.createApplication(bioId);
- applicationRepo.createPutTransaction(bioId, 5).commit();
- assertFromParameter("6", "http://myhost:40555/application/v2/tenant/" + tenant + "/application/foobio/environment/staging/region/baz/instance/quux");
+ ApplicationId applicationId = ApplicationId.from(tenant.value(), "foo", "quux");
+ HttpRequest request = post(Collections.singletonMap(
+ "from",
+ "http://myhost:40555/application/v2/tenant/" + tenant + "/application/foo/environment/test/region/baz/instance/quux"));
+ assertEquals(applicationId, SessionCreateHandler.getFromApplicationId(request));
}
@Test