org.junit.rules.TemporaryFolder#newFile()源码实例Demo

下面列出了org.junit.rules.TemporaryFolder#newFile() 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: iaf   文件: MessageTest.java
@Test
public void testSerializeWithURL() throws Exception {
	TemporaryFolder folder = new TemporaryFolder();
	folder.create();
	File file = folder.newFile();
	writeContentsToFile(file, testString);
	URL source = file.toURL();

	Message in = new Message(source);
	byte[] wire = serializationTester.serialize(in);
	writeContentsToFile(file, "fakeContentAsReplacementOfThePrevious");
	Message out = serializationTester.deserialize(wire);
	
	assertTrue(out.isBinary());
	assertEquals(testString,out.asString());
}
 
源代码2 项目: sonar-tsql-plugin   文件: CoverageSensorTest.java
@Test
public void test() throws Throwable {
	TemporaryFolder folder = new TemporaryFolder();
	folder.create();

	SensorContextTester ctxTester = SensorContextTester.create(folder.getRoot());
	String tempName = "GetStatusMessage.sql";
	String covReport = "test.xml";
	File f = folder.newFile(tempName);
	File coverage = folder.newFile(covReport);

	FileUtils.copyInputStreamToFile(this.getClass().getResourceAsStream("/coverage/Coverage.opencoverxml"),
			coverage);

	FileUtils.copyInputStreamToFile(this.getClass().getResourceAsStream("/coverage/TestCode.sql"), f);
	DefaultInputFile file1 = new TestInputFileBuilder(folder.getRoot().getAbsolutePath(), tempName)
			.initMetadata(new String(Files.readAllBytes(f.toPath()))).setLanguage(TSQLLanguage.KEY).build();
	ctxTester.fileSystem().add(file1);
	ctxTester.settings().setProperty(Constants.COVERAGE_FILE, coverage.getAbsolutePath());
	ctxTester.settings().setProperty(Constants.PLUGIN_SKIP_COVERAGE, false);
	CoverageSensor sut = new CoverageSensor(new SqlCoverCoverageProvider(ctxTester.settings(), ctxTester.fileSystem()));
	sut.execute(ctxTester);
	Assert.assertEquals((int) 2, (int) ctxTester.lineHits(file1.key(), 7));

}
 
源代码3 项目: java-client-api   文件: ServiceCompareTaskTest.java
TestDir(TemporaryFolder testDir) throws IOException {
    String baseSourcePath   = "ml-modules/root/dbfunctiondef/positive/decoratorBase/";
    String customSourcePath  = "ml-modules/root/dbfunctiondef/positive/decoratorCustom/";
    String otherSourcePath   = "ml-modules/root/dbfunctiondef/positive/mimetype/";

    srcDir = testDir.newFolder("src");

    baseServiceDir   = new File(srcDir, baseSourcePath);
    customServiceDir  = new File(srcDir, customSourcePath);
    otherServiceDir   = new File(srcDir, otherSourcePath);

    buildFile = testDir.newFile("build.gradle");
    propsFile = testDir.newFile("gradle.properties");

    baseServiceDir.mkdirs();
    customServiceDir.mkdirs();
    otherServiceDir.mkdirs();

    GradleTestUtil.copyFiles(new File("src/test/" + baseSourcePath),   baseServiceDir);
    GradleTestUtil.copyFiles(new File("src/test/" + customSourcePath), customServiceDir);
    GradleTestUtil.copyFiles(new File("src/test/" + otherSourcePath),  otherServiceDir);
}
 
源代码4 项目: java-client-api   文件: ModuleInitTaskTest.java
TestDir(TemporaryFolder testDir) throws IOException {
  String sourcePath = "ml-modules/root/dbfunctiondef/positive/sessions/";
  String apiFilename = baseName + ".api";

  buildFile = testDir.newFile("build.gradle");
  propsFile = testDir.newFile("gradle.properties");
  srcDir = testDir.newFolder("src");

  sjsOutDir = new File(srcDir, "sjs");
  xqyOutDir = new File(srcDir, "xqy");

  sjsOutDir.mkdirs();
  xqyOutDir.mkdirs();

  sjsAPIFile = new File(sjsOutDir, apiFilename);
  xqyAPIFile = new File(xqyOutDir, apiFilename);

  File srcAPIFile = new File("src/test/" + sourcePath + apiFilename);
  GradleTestUtil.copyTextFile(srcAPIFile, sjsAPIFile);
  GradleTestUtil.copyTextFile(srcAPIFile, xqyAPIFile);
}
 
TestDir(TemporaryFolder testDir) throws IOException {
  String sourcePath = "ml-modules/root/dbfunctiondef/positive/sessions/";

  srcDir = testDir.newFolder("src");
  serviceDir  = new File(srcDir, sourcePath);
  javaBaseDir = new File(srcDir, "main/java");
  buildFile = testDir.newFile("build.gradle");
  propsFile = testDir.newFile("gradle.properties");
  outClass  = new File(javaBaseDir, "com/marklogic/client/test/dbfunction/positive/SessionsBundle.java");

  serviceDir.mkdirs();

  GradleTestUtil.copyFiles(new File("src/test/" + sourcePath), serviceDir);

  javaBaseDir.mkdirs();
}
 
源代码6 项目: batfish   文件: WorkMgrTest.java
@Test
public void testAddToSerializedListNoAddition() throws IOException {
  TemporaryFolder tmp = new TemporaryFolder();
  tmp.create();
  File serializedList = tmp.newFile();
  Path serializedListPath = serializedList.toPath();

  NodeInterfacePair baseInterface = NodeInterfacePair.of("n1", "iface1");

  // Write base serialized list
  List<NodeInterfacePair> interfaces = new ArrayList<>();
  interfaces.add(baseInterface);
  writeFile(serializedListPath, BatfishObjectMapper.writePrettyString(interfaces));

  addToSerializedList(
      serializedListPath, ImmutableList.of(), new TypeReference<List<NodeInterfacePair>>() {});

  // Confirm original interface shows up in the merged list, even if there are no additions
  assertThat(
      BatfishObjectMapper.mapper()
          .readValue(
              CommonUtil.readFile(serializedListPath),
              new TypeReference<List<NodeInterfacePair>>() {}),
      containsInAnyOrder(baseInterface));
}
 
源代码7 项目: batfish   文件: WorkMgrTest.java
@Test
public void testAddToSerializedListNullAddition() throws IOException {
  TemporaryFolder tmp = new TemporaryFolder();
  tmp.create();
  File serializedList = tmp.newFile();
  Path serializedListPath = serializedList.toPath();

  NodeInterfacePair baseInterface = NodeInterfacePair.of("n1", "iface1");

  // Write base serialized list
  List<NodeInterfacePair> interfaces = new ArrayList<>();
  interfaces.add(baseInterface);
  writeFile(serializedListPath, BatfishObjectMapper.writePrettyString(interfaces));

  addToSerializedList(serializedListPath, null, new TypeReference<List<NodeInterfacePair>>() {});

  // Confirm original interface shows up in the merged list, even if addition is null
  assertThat(
      BatfishObjectMapper.mapper()
          .readValue(
              CommonUtil.readFile(serializedListPath),
              new TypeReference<List<NodeInterfacePair>>() {}),
      containsInAnyOrder(baseInterface));
}
 
源代码8 项目: batfish   文件: WorkMgrTest.java
@Test
public void testAddToSerializedListNoList() throws IOException {
  TemporaryFolder tmp = new TemporaryFolder();
  tmp.create();
  File serializedList = tmp.newFile();
  Path serializedListPath = serializedList.toPath();
  serializedList.delete();

  NodeInterfacePair additionalInterface = NodeInterfacePair.of("n2", "iface2");

  addToSerializedList(
      serializedListPath,
      ImmutableList.of(additionalInterface),
      new TypeReference<List<NodeInterfacePair>>() {});

  // Confirm the additional interface shows up in the serialized list, even if the serialized list
  // didn't exist in the first place
  assertThat(
      BatfishObjectMapper.mapper()
          .readValue(
              CommonUtil.readFile(serializedListPath),
              new TypeReference<List<NodeInterfacePair>>() {}),
      containsInAnyOrder(additionalInterface));
}
 
源代码9 项目: iaf   文件: MessageTest.java
@Test
public void testSerializeWithFile() throws Exception {
	TemporaryFolder folder = new TemporaryFolder();
	folder.create();
	File source = folder.newFile();
	writeContentsToFile(source, testString);
	
	Message in = new Message(source);
	byte[] wire = serializationTester.serialize(in);
	writeContentsToFile(source, "fakeContentAsReplacementOfThePrevious");
	Message out = serializationTester.deserialize(wire);
	
	assertTrue(out.isBinary());
	assertEquals(testString,out.asString());
}
 
public static @NotNull IsolatedPluginClassloader buildClassLoader(
        final @NotNull TemporaryFolder temporaryFolder, final @NotNull Class[] classes) throws Exception {

    final JavaArchive javaArchive = ShrinkWrap.create(JavaArchive.class).addClasses(classes);

    final File jarFile = temporaryFolder.newFile();
    javaArchive.as(ZipExporter.class).exportTo(jarFile, true);

    return new IsolatedPluginClassloader(new URL[]{jarFile.toURI().toURL()},
            IsolatedPluginClassLoaderUtil.class.getClassLoader());
}
 
源代码11 项目: konduit-serving   文件: TestUtils.java
public static InferenceConfiguration getConfig(TemporaryFolder trainDir) throws Exception {
    Pair<MultiLayerNetwork, DataNormalization> multiLayerNetwork = TrainUtils.getTrainedNetwork();
    File modelSave = trainDir.newFile("model.zip");
    ModelSerializer.writeModel(multiLayerNetwork.getFirst(), modelSave, false);

    Schema.Builder schemaBuilder = new Schema.Builder();
    schemaBuilder.addColumnDouble("petal_length")
            .addColumnDouble("petal_width")
            .addColumnDouble("sepal_width")
            .addColumnDouble("sepal_height");
    Schema inputSchema = schemaBuilder.build();

    Schema.Builder outputSchemaBuilder = new Schema.Builder();
    outputSchemaBuilder.addColumnDouble("setosa");
    outputSchemaBuilder.addColumnDouble("versicolor");
    outputSchemaBuilder.addColumnDouble("virginica");
    Schema outputSchema = outputSchemaBuilder.build();

    ServingConfig servingConfig = ServingConfig.builder()
            .createLoggingEndpoints(true)
            .build();

    Dl4jStep modelPipelineStep = Dl4jStep.builder()
            .inputName("default")
            .inputColumnName("default", SchemaTypeUtils.columnNames(inputSchema))
            .inputSchema("default", SchemaTypeUtils.typesForSchema(inputSchema))
            .outputSchema("default", SchemaTypeUtils.typesForSchema(outputSchema))
            .path(modelSave.getAbsolutePath())
            .outputColumnName("default", SchemaTypeUtils.columnNames(outputSchema))
            .build();

    return InferenceConfiguration.builder()
            .servingConfig(servingConfig)
            .step(modelPipelineStep)
            .build();
}
 
源代码12 项目: batfish   文件: WorkMgrTest.java
@Test
public void testRemoveFromSerializedListMissingBaseList() throws IOException {
  TemporaryFolder tmp = new TemporaryFolder();
  tmp.create();
  File serializedList = tmp.newFile();
  Path serializedListPath = serializedList.toPath();
  Files.delete(serializedListPath);

  // Remove nothing from a non-existent list
  removeFromSerializedList(
      serializedListPath, ImmutableList.of(), new TypeReference<List<NodeInterfacePair>>() {});

  // Confirm no issue if base list didn't exist
  assertThat(serializedList, not(anExistingFile()));
}
 
源代码13 项目: netbeans   文件: GradleCommandLineTest.java
@Test
public void testJVMArgs2() throws IOException {
    TemporaryFolder root = new TemporaryFolder();
    root.create();
    File props = root.newFile("gradle.properties");
    Files.write(props.toPath(), Arrays.asList("org.gradle.jvmargs=\"-Dfile.encoding=UTF-8\" -Dsomething=\"space value\""));
    List<String> jvmargs = new ArrayList<>();
    GradleCommandLine.addGradleSettingJvmargs(root.getRoot(), jvmargs);
    assertEquals(Arrays.asList("-Dfile.encoding=UTF-8", "-Dsomething=space value"), jvmargs);
}
 
源代码14 项目: sonar-tsql-plugin   文件: CustomChecksSensorTest.java
@Test
public void testTSQLGrammarFiles() throws IOException {
	TemporaryFolder folder = new TemporaryFolder();
	folder.create();
	SensorContextTester ctxTester = SensorContextTester.create(folder.getRoot());

	ctxTester.settings().setProperty(Constants.PLUGIN_SKIP, false);
	ctxTester.settings().setProperty(Constants.PLUGIN_SKIP_CUSTOM_RULES, false);
	ctxTester.settings().setProperty(Constants.PLUGIN_SKIP_CUSTOM, false);
	ctxTester.settings().setProperty(Constants.PLUGIN_MAX_FILE_SIZE, 100);
	String dirPath = "..\\grammars\\tsql";
	File dir = new File(dirPath);
	Collection<File> files = FileUtils.listFiles(dir, new String[] { "sql" }, true);
	for (File f : files) {
		String tempName = f.getName() + System.nanoTime();
		File dest = folder.newFile(tempName);
		FileUtils.copyFile(f, dest);

		DefaultInputFile file1 = new TestInputFileBuilder(folder.getRoot().getAbsolutePath(), tempName)
				.initMetadata(new String(Files.readAllBytes(f.toPath()))).setLanguage(TSQLLanguage.KEY).build();
		ctxTester.fileSystem().add(file1);

	}
	CustomChecksSensor sensor = new CustomChecksSensor();
	sensor.execute(ctxTester);
	Collection<Issue> issues = ctxTester.allIssues();
	Assert.assertEquals(183, issues.size());

}
 
源代码15 项目: swift-explorer   文件: TestUtils.java
public static File getTestFile (TemporaryFolder tmpFolder, String fileName, long fileSize) throws IOException
{
    byte data [] = new byte[(int) fileSize] ;
    for (int i = 0 ; i < fileSize ; ++i)
    	data[i] = (byte)(Math.random() * 256) ;

    File file = tmpFolder.newFile(fileName) ;
    
	// generate test file
	FileOutputStream out = new FileOutputStream(file);
  	out.write(data);
	out.close();
    
    return file ;
}
 
源代码16 项目: batfish   文件: WorkMgrTest.java
@Test
public void testAddToSerializedList() throws IOException {
  TemporaryFolder tmp = new TemporaryFolder();
  tmp.create();
  File serializedList = tmp.newFile();
  Path serializedListPath = serializedList.toPath();

  NodeInterfacePair baseInterface = NodeInterfacePair.of("n1", "iface1");
  NodeInterfacePair additionalInterface = NodeInterfacePair.of("n2", "iface2");

  // Write base serialized list
  List<NodeInterfacePair> interfaces = new ArrayList<>();
  interfaces.add(baseInterface);
  writeFile(serializedListPath, BatfishObjectMapper.writePrettyString(interfaces));

  addToSerializedList(
      serializedListPath,
      ImmutableList.of(additionalInterface),
      new TypeReference<List<NodeInterfacePair>>() {});

  // Confirm the additional and original interfaces show up in the merged list
  assertThat(
      BatfishObjectMapper.mapper()
          .readValue(
              CommonUtil.readFile(serializedListPath),
              new TypeReference<List<NodeInterfacePair>>() {}),
      containsInAnyOrder(baseInterface, additionalInterface));
}
 
源代码17 项目: batfish   文件: WorkMgrTest.java
@Test
public void testAddToSerializedListNoListNoAddition() throws IOException {
  TemporaryFolder tmp = new TemporaryFolder();
  tmp.create();
  File serializedList = tmp.newFile();
  Path serializedListPath = serializedList.toPath();
  serializedList.delete();

  addToSerializedList(
      serializedListPath, ImmutableList.of(), new TypeReference<List<NodeInterfacePair>>() {});

  // Confirm no file was created (since there was no list to begin with and nothing was added)
  assertThat(serializedList, not(FileMatchers.anExistingFile()));
}
 
源代码18 项目: batfish   文件: WorkMgrTest.java
@Test
public void testRemoveFromSerializedList() throws IOException {
  TemporaryFolder tmp = new TemporaryFolder();
  tmp.create();
  File serializedList = tmp.newFile();
  Path serializedListPath = serializedList.toPath();

  NodeInterfacePair baseInterface1 = NodeInterfacePair.of("n1", "iface1");
  NodeInterfacePair baseInterface2 = NodeInterfacePair.of("n2", "iface2");

  // Write base serialized list
  List<NodeInterfacePair> interfaces = new ArrayList<>();
  interfaces.add(baseInterface1);
  interfaces.add(baseInterface2);
  writeFile(serializedListPath, BatfishObjectMapper.writePrettyString(interfaces));

  removeFromSerializedList(
      serializedListPath,
      ImmutableList.of(baseInterface1),
      new TypeReference<List<NodeInterfacePair>>() {});

  // Confirm only one interface shows up
  assertThat(
      BatfishObjectMapper.mapper()
          .readValue(
              CommonUtil.readFile(serializedListPath),
              new TypeReference<List<NodeInterfacePair>>() {}),
      contains(baseInterface2));
}
 
@NotNull
public static SubscriptionAuthorizer getIsolatedSubscriptionAuthorizer(final TemporaryFolder temporaryFolder, @NotNull final ClassLoader classLoader) throws Exception {

    final JavaArchive javaArchive = ShrinkWrap.create(JavaArchive.class)
            .addClass("util.TestAuthorizerUtil$TestSubscriptionAuthorizer");

    final File jarFile = temporaryFolder.newFile();
    javaArchive.as(ZipExporter.class).exportTo(jarFile, true);

    //This classloader contains the classes from the jar file
    final IsolatedPluginClassloader cl = new IsolatedPluginClassloader(new URL[]{jarFile.toURI().toURL()}, classLoader);

    final List<Authorizer> authorizers = new ArrayList<>();

    final Class<?> subscriptionAuthorizerClass = cl.loadClass("util.TestAuthorizerUtil$TestSubscriptionAuthorizer");

    final SubscriptionAuthorizer subscriptionAuthorizer = (SubscriptionAuthorizer) subscriptionAuthorizerClass.newInstance();

    return subscriptionAuthorizer;

}
 
源代码20 项目: writelatex-git-bridge   文件: SqliteDBStoreTest.java
@Before
public void setup() throws IOException {
    TemporaryFolder tmpFolder = new TemporaryFolder();
    tmpFolder.create();
    dbStore = new SqliteDBStore(tmpFolder.newFile("dbStore.db"));
}