aboutsummaryrefslogtreecommitdiffstats
path: root/config-model/src/test/java/com/yahoo/config/model/ApplicationDeployTest.java
diff options
context:
space:
mode:
Diffstat (limited to 'config-model/src/test/java/com/yahoo/config/model/ApplicationDeployTest.java')
-rw-r--r--config-model/src/test/java/com/yahoo/config/model/ApplicationDeployTest.java140
1 files changed, 74 insertions, 66 deletions
diff --git a/config-model/src/test/java/com/yahoo/config/model/ApplicationDeployTest.java b/config-model/src/test/java/com/yahoo/config/model/ApplicationDeployTest.java
index ec5850b95b9..c1dd62316db 100644
--- a/config-model/src/test/java/com/yahoo/config/model/ApplicationDeployTest.java
+++ b/config-model/src/test/java/com/yahoo/config/model/ApplicationDeployTest.java
@@ -18,10 +18,9 @@ import com.yahoo.schema.Schema;
import com.yahoo.vespa.config.ConfigDefinition;
import com.yahoo.vespa.config.ConfigDefinitionKey;
import com.yahoo.vespa.model.VespaModel;
-import org.junit.After;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.TemporaryFolder;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
import org.xml.sax.SAXException;
import java.io.File;
@@ -36,22 +35,18 @@ import java.util.Map;
import java.util.Set;
import java.util.jar.JarEntry;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
+import static org.junit.jupiter.api.Assertions.*;
public class ApplicationDeployTest {
private static final String TESTDIR = "src/test/cfg/application/";
private static final String TEST_SCHEMAS_DIR = TESTDIR + "app1/schemas/";
- @Rule
- public TemporaryFolder tmpFolder = new TemporaryFolder();
+ @TempDir
+ public File tmpFolder;
@Test
- public void testVespaModel() throws SAXException, IOException {
+ void testVespaModel() throws SAXException, IOException {
ApplicationPackageTester tester = ApplicationPackageTester.create(TESTDIR + "app1");
new VespaModel(tester.app());
List<Schema> schemas = tester.getSchemas();
@@ -72,11 +67,11 @@ public class ApplicationDeployTest {
}
}
assertEquals(Set.of(new File(TEST_SCHEMAS_DIR + "laptop.sd"),
- new File(TEST_SCHEMAS_DIR + "music.sd"),
- new File(TEST_SCHEMAS_DIR + "pc.sd"),
- new File(TEST_SCHEMAS_DIR + "product.sd"),
- new File(TEST_SCHEMAS_DIR + "sock.sd")),
- new HashSet<>(tester.app().getSearchDefinitionFiles()));
+ new File(TEST_SCHEMAS_DIR + "music.sd"),
+ new File(TEST_SCHEMAS_DIR + "pc.sd"),
+ new File(TEST_SCHEMAS_DIR + "product.sd"),
+ new File(TEST_SCHEMAS_DIR + "sock.sd")),
+ new HashSet<>(tester.app().getSearchDefinitionFiles()));
List<FilesApplicationPackage.Component> components = tester.app().getComponents();
assertEquals(1, components.size());
@@ -104,7 +99,7 @@ public class ApplicationDeployTest {
}
@Test
- public void testGetFile() throws IOException {
+ void testGetFile() throws IOException {
ApplicationPackageTester tester = ApplicationPackageTester.create(TESTDIR + "app1");
try (Reader foo = tester.app().getFile(Path.fromString("files/foo.json")).createReader()) {
assertEquals(IOUtils.readAll(foo), "foo : foo\n");
@@ -128,7 +123,7 @@ public class ApplicationDeployTest {
}
@Test
- public void include_dirs_are_included() {
+ void include_dirs_are_included() {
ApplicationPackageTester tester = ApplicationPackageTester.create(TESTDIR + "include_dirs");
Set<String> includeDirs = new HashSet<>(tester.app().getUserIncludeDirs());
@@ -136,12 +131,12 @@ public class ApplicationDeployTest {
}
@Test
- public void non_existent_include_dir_is_not_allowed() throws Exception {
- File appDir = tmpFolder.newFolder("non-existent-include");
+ void non_existent_include_dir_is_not_allowed() throws Exception {
+ File appDir = newFolder(tmpFolder, "non-existent-include");
String services =
"<services version='1.0'>" +
- " <include dir='non-existent' />" +
- "</services>\n";
+ " <include dir='non-existent' />" +
+ "</services>\n";
IOUtils.writeFile(new File(appDir, "services.xml"), services, false);
try {
@@ -149,13 +144,13 @@ public class ApplicationDeployTest {
fail("Expected exception due to non-existent include dir");
} catch (IllegalArgumentException e) {
assertEquals("Cannot include directory 'non-existent', as it does not exist. Directory must reside in application package, and path must be given relative to application package.",
- e.getMessage());
+ e.getMessage());
}
}
@Test
- public void testThatModelIsRebuiltWhenSearchDefinitionIsAdded() throws IOException {
- File tmpDir = tmpFolder.getRoot();
+ void testThatModelIsRebuiltWhenSearchDefinitionIsAdded() throws IOException {
+ File tmpDir = tmpFolder;
IOUtils.copyDirectory(new File(TESTDIR, "app1"), tmpDir);
ApplicationPackageTester tester = ApplicationPackageTester.create(tmpDir.getAbsolutePath());
assertEquals(5, tester.getSchemas().size());
@@ -166,55 +161,57 @@ public class ApplicationDeployTest {
}
@Test
- public void testThatAppWithDeploymentXmlIsValid() throws IOException {
- File tmpDir = tmpFolder.getRoot();
+ void testThatAppWithDeploymentXmlIsValid() throws IOException {
+ File tmpDir = tmpFolder;
IOUtils.copyDirectory(new File(TESTDIR, "app1"), tmpDir);
ApplicationPackageTester.create(tmpDir.getAbsolutePath());
}
- @Test(expected = IllegalArgumentException.class)
- public void testThatAppWithIllegalDeploymentXmlIsNotValid() throws IOException {
- File tmpDir = tmpFolder.getRoot();
- IOUtils.copyDirectory(new File(TESTDIR, "app_invalid_deployment_xml"), tmpDir);
- ApplicationPackageTester.create(tmpDir.getAbsolutePath());
+ @Test
+ void testThatAppWithIllegalDeploymentXmlIsNotValid() throws IOException {
+ assertThrows(IllegalArgumentException.class, () -> {
+ File tmpDir = tmpFolder;
+ IOUtils.copyDirectory(new File(TESTDIR, "app_invalid_deployment_xml"), tmpDir);
+ ApplicationPackageTester.create(tmpDir.getAbsolutePath());
+ });
}
@Test
- public void testComplicatedDeploymentSpec() throws IOException {
- File tmpDir = tmpFolder.getRoot();
+ void testComplicatedDeploymentSpec() throws IOException {
+ File tmpDir = tmpFolder;
IOUtils.copyDirectory(new File(TESTDIR, "app_complicated_deployment_spec"), tmpDir);
ApplicationPackageTester.create(tmpDir.getAbsolutePath());
}
@Test
- public void testAppWithEmptyProdRegion() throws IOException {
- File tmpDir = tmpFolder.getRoot();
+ void testAppWithEmptyProdRegion() throws IOException {
+ File tmpDir = tmpFolder;
IOUtils.copyDirectory(new File(TESTDIR, "empty_prod_region_in_deployment_xml"), tmpDir);
ApplicationPackageTester.create(tmpDir.getAbsolutePath());
}
@Test
- public void testThatAppWithInvalidParallelDeploymentFails() throws IOException {
+ void testThatAppWithInvalidParallelDeploymentFails() throws IOException {
String expectedMessage = "4: <staging/>\n" +
- "5: <prod global-service-id=\"query\">\n" +
- "6: <parallel>\n" +
- "7: <instance id=\"hello\" />\n" +
- "8: </parallel>\n" +
- "9: </prod>\n" +
- "10:</deployment>\n";
- File tmpDir = tmpFolder.getRoot();
+ "5: <prod global-service-id=\"query\">\n" +
+ "6: <parallel>\n" +
+ "7: <instance id=\"hello\" />\n" +
+ "8: </parallel>\n" +
+ "9: </prod>\n" +
+ "10:</deployment>\n";
+ File tmpDir = tmpFolder;
IOUtils.copyDirectory(new File(TESTDIR, "invalid_parallel_deployment_xml"), tmpDir);
try {
ApplicationPackageTester.create(tmpDir.getAbsolutePath());
fail("Expected exception");
} catch (IllegalArgumentException e) {
assertEquals("Invalid XML according to XML schema, error in deployment.xml: element \"instance\" not allowed here; expected the element end-tag or element \"delay\", \"region\", \"steps\" or \"test\" [7:30], input:\n" + expectedMessage,
- e.getMessage());
+ e.getMessage());
}
}
@Test
- public void testConfigDefinitionsFromJars() {
+ void testConfigDefinitionsFromJars() {
String appName = "src/test/cfg//application/app1";
FilesApplicationPackage app = FilesApplicationPackage.fromFile(new File(appName), false);
Map<ConfigDefinitionKey, UnparsedConfigDefinition> defs = app.getAllExistingConfigDefs();
@@ -222,25 +219,25 @@ public class ApplicationDeployTest {
}
@Test
- public void testMetaData() throws IOException {
+ void testMetaData() throws IOException {
File tmp = Files.createTempDir();
String appPkg = TESTDIR + "app1";
IOUtils.copyDirectory(new File(appPkg), tmp);
ApplicationId applicationId = ApplicationId.from("tenant1", "application1", "instance1");
DeployData deployData = new DeployData("bar",
- applicationId,
- 13L,
- false,
- 1337L,
- 3L);
+ applicationId,
+ 13L,
+ false,
+ 1337L,
+ 3L);
FilesApplicationPackage app = FilesApplicationPackage.fromFileWithDeployData(tmp, deployData);
app.writeMetaData();
FilesApplicationPackage newApp = FilesApplicationPackage.fromFileWithDeployData(tmp, deployData);
ApplicationMetaData meta = newApp.getMetaData();
assertEquals("bar", meta.getDeployPath());
assertEquals(applicationId, meta.getApplicationId());
- assertEquals(13L, (long)meta.getDeployTimestamp());
- assertEquals(1337L, (long)meta.getGeneration());
+ assertEquals(13L, (long) meta.getDeployTimestamp());
+ assertEquals(1337L, (long) meta.getGeneration());
assertEquals(3L, meta.getPreviousActiveGeneration());
String checksum = meta.getChecksum();
assertNotNull(checksum);
@@ -257,7 +254,7 @@ public class ApplicationDeployTest {
}
@Test
- public void testGetJarEntryName() {
+ void testGetJarEntryName() {
JarEntry e = new JarEntry("/schemas/foo.sd");
assertEquals(ApplicationPackage.getFileName(e), "foo.sd");
e = new JarEntry("bar");
@@ -267,7 +264,7 @@ public class ApplicationDeployTest {
}
@Test
- public void testGetJarEntryNameForLegacyPath() {
+ void testGetJarEntryNameForLegacyPath() {
JarEntry e = new JarEntry("/searchdefinitions/foo.sd");
assertEquals(ApplicationPackage.getFileName(e), "foo.sd");
e = new JarEntry("bar");
@@ -276,7 +273,7 @@ public class ApplicationDeployTest {
assertEquals(ApplicationPackage.getFileName(e), "");
}
- @After
+ @AfterEach
public void cleanDirs() {
IOUtils.recursiveDeleteDir(new File(TESTDIR + "app1/myDir"));
IOUtils.recursiveDeleteDir(new File(TESTDIR + "app1/searchdefinitions/myDir2"));
@@ -284,7 +281,7 @@ public class ApplicationDeployTest {
}
@SuppressWarnings("ResultOfMethodCallIgnored")
- @After
+ @AfterEach
public void cleanFiles() {
new File(new File(TESTDIR + "app1"),"foo.txt").delete();
new File(new File(TESTDIR + "app1"),"searchdefinitions/bar.text").delete();
@@ -295,13 +292,13 @@ public class ApplicationDeployTest {
* Tests that an invalid jar is identified as not being a jar file
*/
@Test
- public void testInvalidJar() {
+ void testInvalidJar() {
try {
FilesApplicationPackage.getComponents(new File("src/test/cfg/application/validation/invalidjar_app"));
fail();
} catch (IllegalArgumentException e) {
assertEquals("Error opening jar file 'invalid.jar'. Please check that this is a valid jar file",
- e.getMessage());
+ e.getMessage());
}
}
@@ -312,7 +309,7 @@ public class ApplicationDeployTest {
* definition without version in file name
*/
@Test
- public void testConfigDefinitionsAndNamespaces() {
+ void testConfigDefinitionsAndNamespaces() {
final File appDir = new File("src/test/cfg/application/configdeftest");
FilesApplicationPackage app = FilesApplicationPackage.fromFile(appDir);
@@ -330,10 +327,21 @@ public class ApplicationDeployTest {
assertEquals("bar", def.getName());
}
- @Test(expected=IllegalArgumentException.class)
- public void testDifferentNameOfSdFileAndSearchName() {
- ApplicationPackageTester tester = ApplicationPackageTester.create(TESTDIR + "sdfilenametest");
- new DeployState.Builder().applicationPackage(tester.app()).build();
+ @Test
+ void testDifferentNameOfSdFileAndSearchName() {
+ assertThrows(IllegalArgumentException.class, () -> {
+ ApplicationPackageTester tester = ApplicationPackageTester.create(TESTDIR + "sdfilenametest");
+ new DeployState.Builder().applicationPackage(tester.app()).build();
+ });
+ }
+
+ private static File newFolder(File root, String... subDirs) throws IOException {
+ String subFolder = String.join("/", subDirs);
+ File result = new File(root, subFolder);
+ if (!result.mkdirs()) {
+ throw new IOException("Couldn't create folders " + root);
+ }
+ return result;
}
}