@Test public void testConfigList() throws Exception { addPropsToUserConfig(); test.execute("config-list", 15, TimeUnit.SECONDS); assertThat(test.getStdOut(), containsString("key1=user: [userValue1]")); assertThat(test.getStdOut(), containsString("key2=user: [userValue2]")); }
@Test public void testDateCommandWithIllegalPattern() throws Exception { Result result = shellTest.execute("date --pattern foo", 15, TimeUnit.SECONDS); Assert.assertTrue(result instanceof Failed); String out = shellTest.getStdErr(); Assert.assertThat(out, containsString("Illegal date pattern: foo")); }
@Test(timeout = 10000) public void testCatCommandInvalidArgument() throws Exception { Result result = shellTest.execute("cat foo bar", 5, TimeUnit.SECONDS); Assert.assertTrue(result instanceof Failed); String out = shellTest.getStdOut(); Assert.assertThat(out, containsString("cat: foo: No such file or directory")); Assert.assertThat(out, containsString("cat: bar: No such file or directory")); }
@Test public void testDateCommandWithLegalPattern() throws Exception { String formattedDate = new SimpleDateFormat("yyyyMMdd").format(new Date()); Result result = shellTest.execute("date --pattern yyyyMMdd", 15, TimeUnit.SECONDS); Assert.assertThat(result, is(not(instanceOf(Failed.class)))); String out = shellTest.getStdOut(); Assert.assertThat(out, containsString(formattedDate)); }
@Test public void testConfigSetProperty() throws Exception { assertFalse( test.execute("config-set --key key1 --value userValue1", 15, TimeUnit.SECONDS) instanceof Failed); test.clearScreen(); assertFalse(test.execute("config-list", 15, TimeUnit.SECONDS) instanceof Failed); assertThat(test.getStdOut(), containsString("key1=user: [userValue1]")); }
@Test public void testConfigListInProject() throws Exception { Project project = projectFactory.createTempProject(); Configuration projectConfig = project.getFacet(ConfigurationFacet.class).getConfiguration(); addPropsToProjectConfig(projectConfig); test.getShell().setCurrentResource(project.getRoot()); test.execute("config-list", 15, TimeUnit.SECONDS); assertThat(test.getStdOut(), containsString("key2=project: [projectValue2]")); assertThat(test.getStdOut(), containsString("key3=project: [projectValue3]")); }
@Test public void testConfigSetPropertyListInProject() throws Exception { Project project = projectFactory.createTempProject(); test.getShell().setCurrentResource(project.getRoot()); test.execute("config-set --key key2 --value projectValue2 --local", 15, TimeUnit.SECONDS); test.execute("config-set --key key3 --value projectValue3 --local", 15, TimeUnit.SECONDS); assertFalse(test.execute("config-list", 15, TimeUnit.SECONDS) instanceof Failed); assertThat(test.getStdOut(), containsString("key2=project: [projectValue2]")); assertThat(test.getStdOut(), containsString("key3=project: [projectValue3]")); }
@Test public void testCatCommand() throws Exception { Project project = projectFactory.createTempProject(); File target = new File(project.getRoot().getFullyQualifiedName(), "test.java"); target.createNewFile(); FileResource<?> source = project.getRoot().getChild(target.getName()).reify(FileResource.class); source.setContents("public void test() {}"); shellTest.execute("cat " + source.getFullyQualifiedName(), 5, TimeUnit.SECONDS); Assert.assertThat(shellTest.getStdOut(), CoreMatchers.containsString("test()")); }
@Test public void testCatColoredCommand() throws Exception { Project project = projectFactory.createTempProject(); File target = new File(project.getRoot().getFullyQualifiedName(), "test.java"); target.createNewFile(); FileResource<?> source = project.getRoot().getChild(target.getName()).reify(FileResource.class); source.setContents("public void test() {}"); shellTest.execute("cat " + source.getFullyQualifiedName() + " --color", 5, TimeUnit.SECONDS); // the string should be colors, so there are color codes between the statements Assert.assertThat( shellTest.getStdOut(), CoreMatchers.not(CoreMatchers.containsString("public void"))); }
@Test public void checkCommandShell() throws Exception { shellTest.getShell().setCurrentResource(project.getRoot()); shellTest.execute( "cdi-new-bean --named DummyBean --target-package org.test", 10, TimeUnit.SECONDS); Result result = shellTest.execute( "cdi-add-observer-method --named dummy --event-type java.lang.String --target-class org.test.DummyBean", 10, TimeUnit.SECONDS); Assert.assertThat(result, not(instanceOf(Failed.class))); Assert.assertTrue(project.hasFacet(CDIFacet.class)); }
@SuppressWarnings("unchecked") @Test public void checkCommandShell() throws Exception { shellTest.getShell().setCurrentResource(project.getRoot()); Result result = shellTest.execute( ("jpa-new-entity --named Customer --target-package org.lincoln --id-strategy AUTO --table-name CUSTOMER_TABLE"), 10, TimeUnit.SECONDS); Assert.assertThat(result, not(instanceOf(Failed.class))); Assert.assertTrue(project.hasFacet(JPAFacet.class)); List<JavaClass<?>> allEntities = project.getFacet(JPAFacet.class).getAllEntities(); Assert.assertEquals(1, allEntities.size()); JavaClass<?> customerEntity = allEntities.get(0); Assert.assertTrue(customerEntity.hasAnnotation(Table.class)); Assert.assertEquals( "CUSTOMER_TABLE", customerEntity.getAnnotation(Table.class).getStringValue("name")); }
@Before public void setUp() throws Exception { test.clearScreen(); }
@After public void tearDown() throws Exception { userConfig.clearProperty("key1"); userConfig.clearProperty("key2"); test.close(); }
@After public void tearDown() throws Exception { shellTest.close(); }
@Test public void testDateCommandWithDefaultPattern() throws Exception { Result result = shellTest.execute("date", 15, TimeUnit.SECONDS); Assert.assertThat(result, is(not(instanceOf(Failed.class)))); }