Search in sources :

Example 1 with AnnotatedComponent

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);
}
Also used : AnnotatedComponent(test.AnnotatedComponent) Pojoization(org.apache.felix.ipojo.manipulator.Pojoization) FileOutputStream(java.io.FileOutputStream) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) File(java.io.File) Test(org.junit.Test)

Aggregations

BufferedReader (java.io.BufferedReader)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 FileReader (java.io.FileReader)1 Pojoization (org.apache.felix.ipojo.manipulator.Pojoization)1 Test (org.junit.Test)1 AnnotatedComponent (test.AnnotatedComponent)1