public void setExpectations(Expectations expectations) { try { expectations.allowing(mock).getCanonicalFile(); expectations.will(expectations.returnValue(mock)); } catch (IOException th) { // ignore } expectations.allowing(mock).isFile(); expectations.will(expectations.returnValue(isFile)); expectations.allowing(mock).getName(); expectations.will(expectations.returnValue(name)); expectations.allowing(mock).exists(); expectations.will(expectations.returnValue(true)); ArrayList<File> mockChildren = new ArrayList<File>(children.size()); for (MockFile child : children) { mockChildren.add(child.getMock()); child.setExpectations(expectations); } expectations.allowing(mock).listFiles(); expectations.will( expectations.returnValue(mockChildren.toArray(new File[mockChildren.size()]))); }
@Test public void rootDirEmpty() throws IOException { final MockFile root = new MockFile(context, "root", false); walker = new DefaultDirectoryWalker(visitor); root.setExpectations(); walker.start(root.getMock()); }
@Test public void walkDepthFirst() throws IOException { walker = new DefaultDirectoryWalker(visitor).depthFirst(); final MockFile root = new MockFile(context, "root", false); final MockFile rootFile1 = root.addFile("rootFile1"); final MockFile dir1 = root.addDir("dir1"); final MockFile dirFile1 = dir1.addFile("dirFile1"); final MockFile dirFile2 = dir1.addFile("dirFile2"); final MockFile rootFile2 = root.addFile("rootFile2"); root.setExpectations(); final Sequence visiting = context.sequence("visiting"); context.checking( new Expectations() { { one(visitor).visitFile(with(file(rootFile1))); inSequence(visiting); one(visitor).visitFile(with(file(rootFile2))); inSequence(visiting); one(visitor).visitFile(with(file(dirFile1))); inSequence(visiting); one(visitor).visitFile(with(file(dirFile2))); inSequence(visiting); one(visitor).visitDir(with(file(dir1))); inSequence(visiting); } }); walker.start(root.getMock()); }
@Test public void testPropertiesParseUtfKey() throws Exception { configFile.setFileContents( " gsa.hostname=not_used\n" + "how\\u2202you= i am happy. how are you?\n"); config.load(configFile); assertEquals("i am happy. how are you?", config.getValue("how\u2202you")); }
@Test public void testGetTransformPipelineSpecValid() throws Exception { final List<Map<String, String>> golden = new ArrayList<Map<String, String>>(); { Map<String, String> map; map = new HashMap<String, String>(); map.put("name", "trans1"); map.put("key1", "value1"); golden.add(map); map = new HashMap<String, String>(); map.put("name", "trans2"); map.put("key2", "value2"); map.put("key3", "value3"); golden.add(map); map = new HashMap<String, String>(); map.put("name", "trans3"); golden.add(map); } configFile.setFileContents( "metadata.transform.pipeline = trans1, trans2 ,trans3\n" + "metadata.transform.pipeline.trans1.key1=value1\n" + "metadata.transform.pipeline.trans2.key2=value2\n" + "metadata.transform.pipeline.trans2.key3=value3\n"); config.setValue("gsa.hostname", "notreal"); config.load(configFile); assertEquals(golden, config.getMetadataTransformPipelineSpec()); }
@Test public void testPropertiesParseKeyEscapedWhitespace() throws Exception { configFile.setFileContents( " gsa.hostname=not_used\n" + " \\ \\ Tru\\ \\ th\\ \\ : Beauty"); config.load(configFile); assertEquals("Beauty", config.getValue(" Tru th ")); }
public RelativePath getRelativePath() { if (parent == null) { return new RelativePath(isFile); } else { return parent.getRelativePath().append(isFile, name); } }
@Test public void testGetTransformPipelineSpecInValid() throws Exception { configFile.setFileContents("metadata.transform.pipeline=name1, ,name3\n"); config.setValue("gsa.hostname", "notreal"); config.load(configFile); thrown.expect(RuntimeException.class); config.getMetadataTransformPipelineSpec(); }
// TODO(ejona): Enable test once config allows gsa.hostname changes. // **DISABLED** @Test public void testConfigModifiedInvalid() throws Exception { configFile.setFileContents("gsa.hostname=notreal\n"); config.load(configFile); assertEquals("notreal", config.getGsaHostname()); // Missing gsa.hostname. configFile.setFileContents(""); configFile.setLastModified(configFile.lastModified() + 1); boolean threwException = false; try { config.ensureLatestConfigLoaded(); } catch (IllegalStateException e) { threwException = true; } assertTrue(threwException); assertEquals("notreal", config.getGsaHostname()); }
@Test public void testPropertiesParseUtfValue() throws Exception { configFile.setFileContents( " gsa.hostname=not_used\n" + "howyou = \\u2202i am happy\\u2202. how are you?\\u2202\\u2202\n"); config.load(configFile); assertEquals("\u2202i am happy\u2202. how are you?\u2202\u2202", config.getValue("howyou")); }
@Test public void walkSingleFile() throws IOException { walker = new DefaultDirectoryWalker(visitor); final MockFile root = new MockFile(context, "root", false); final MockFile fileToCopy = root.addFile("file.txt"); fileToCopy.setExpectations(); context.checking( new Expectations() { { one(visitor).visitFile(with(file(fileToCopy))); } }); walker.start(fileToCopy.getMock()); }
@Test public void testConfigModificationDetection() throws Exception { configFile.setFileContents("adaptor.fullListingSchedule=1\n"); config.setValue("gsa.hostname", "notreal"); config.load(configFile); assertEquals("notreal", config.getGsaHostname()); assertEquals("1", config.getAdaptorFullListingSchedule()); assertEquals(configFile, config.getConfigFile()); final List<ConfigModificationEvent> events = new LinkedList<ConfigModificationEvent>(); ConfigModificationListener listener = new ConfigModificationListener() { @Override public void configModified(ConfigModificationEvent ev) { events.add(ev); } }; configFile.setFileContents("adaptor.fullListingSchedule=2\n"); config.addConfigModificationListener(listener); config.ensureLatestConfigLoaded(); assertEquals("1", config.getAdaptorFullListingSchedule()); assertEquals(0, events.size()); configFile.setLastModified(configFile.lastModified() + 1); config.ensureLatestConfigLoaded(); assertEquals("2", config.getAdaptorFullListingSchedule()); assertEquals("notreal", config.getGsaHostname()); assertEquals(1, events.size()); assertEquals(1, events.get(0).getModifiedKeys().size()); assertTrue(events.get(0).getModifiedKeys().contains("adaptor.fullListingSchedule")); events.clear(); // Change nothing. configFile.setLastModified(configFile.lastModified() + 1); config.ensureLatestConfigLoaded(); assertEquals(0, events.size()); assertEquals("2", config.getAdaptorFullListingSchedule()); assertEquals("notreal", config.getGsaHostname()); config.removeConfigModificationListener(listener); configFile.setFileContents("adaptor.fullListingSchedule=3\n"); configFile.setLastModified(configFile.lastModified() + 1); config.ensureLatestConfigLoaded(); assertEquals(0, events.size()); assertEquals("3", config.getAdaptorFullListingSchedule()); assertEquals("notreal", config.getGsaHostname()); }
@Test public void testPropertiesParseMultiline() throws Exception { configFile.setFileContents( " gsa.hostname=not_used\n" + "fruits apple, banana, pear, \\\n" + " cantaloupe, watermelon, \\\n" + " kiwi, mango\n\n"); config.load(configFile); String golden = "apple, banana, pear, cantaloupe, watermelon, kiwi, mango"; assertEquals(golden, config.getValue("fruits")); }
@Test public void testGetTransformPipelineSpecEmpty() throws Exception { configFile.setFileContents("metadata.transform.pipeline=\n"); config.load(configFile); assertEquals(Collections.emptyList(), config.getMetadataTransformPipelineSpec()); }
@Test public void testPropertiesParseEscapeASlash6() throws Exception { configFile.setFileContents(" gsa.hostname=not_used\n" + "slash= \\\\\\\t\\\\\\\f"); config.load(configFile); assertEquals("\\\t\\\f", config.getValue("slash")); }
public void testNoAdminHostname() throws Exception { configFile.setFileContents("gsa.hostname=feedhost\n"); config.load(configFile); assertEquals(config.getGsaHostname(), config.getGsaAdminHostname()); }
public MockFile addDir(String name) { MockFile child = new MockFile(context, name, false); child.setParent(this); children.add(child); return child; }
@Test public void testSimplestPropertiesParse() throws Exception { configFile.setFileContents(" \t gsa.hostname \t = feedhost bob\n"); config.load(configFile); assertEquals("feedhost bob", config.getValue("gsa.hostname")); }
@Test public void testPropertiesParseColon2() throws Exception { configFile.setFileContents(" gsa.hostname=not_used\n" + " Truth :Beauty"); config.load(configFile); assertEquals("Beauty", config.getValue("Truth")); }