use of test.AnnotatedComponent in project felix by apache.
the class DirManipulationTest method testManifestLocationKept.
/**
* Test case for FELIX-3466.
*
* Checks if directory manipulation, uses the supplied manifest file as
* output.
*
* @throws IOException
*/
@Test
public void testManifestLocationKept() throws IOException {
Pojoization pojoizator = new Pojoization();
File tmpDir = null, manifestFile = null, testClass = null;
// To obtain OS's temp directory.
File tmpFile = File.createTempFile("pojodir", ".dir");
String tmpPath = tmpFile.getAbsolutePath();
tmpFile.delete();
// Creating directory on temp location
tmpDir = new File(tmpPath);
tmpDir.mkdir();
tmpDir.deleteOnExit();
// Create manifest file under temp directory
manifestFile = new File(tmpDir, "MANIFEST.MF");
new FileOutputStream(manifestFile).write("Manifest-Version: 1.0\r\n".getBytes());
manifestFile.deleteOnExit();
// Just to ensure it is not deleted later from test classes.
AnnotatedComponent safe;
// Annotated Class File
File annotedClassPackage = new File(tmpDir, "test");
annotedClassPackage.deleteOnExit();
annotedClassPackage.mkdir();
testClass = new File(annotedClassPackage, "AnnotatedComponent.class");
testClass.deleteOnExit();
FileOutputStream os = new FileOutputStream(testClass);
os.write(ManipulatorTest.getBytesFromFile(new File("target/test-classes/test/AnnotatedComponent.class")));
os.close();
// Issue directory manipulation
pojoizator.directoryPojoization(tmpDir, null, manifestFile, null);
// Check if supplied manifest file is altered in place
BufferedReader fi = new BufferedReader(new FileReader(manifestFile));
String manifestLine;
while ((manifestLine = fi.readLine()) != null) {
if (manifestLine.contains("iPOJO-Components")) {
assertTrue(true);
return;
}
}
assertTrue("Directory Manipulation didn't use supplied manifest file as output", false);
}
Aggregations