Package org.rhq.plugins.jbossas

Examples of org.rhq.plugins.jbossas.ApplicationComponent


    @Test
    public void testDiscoverDeployedPackagesWithDisplayVersionAndSha256Generation() throws Exception {
        //create the object under test as a partial mock because only one
        //public method will be tested, while the rest will be mocked.
        ApplicationComponent objectUnderTest = mock(ApplicationComponent.class);

        //tell the method story as it happens: mock or create dependencies and configure
        //those dependencies to get the method under test to completion.
        PackageType mockPackageType = mock(PackageType.class);

        @SuppressWarnings("unchecked")
        ResourceContext<JBossASServerComponent<?>> mockResourceContext = mock(ResourceContext.class);
        when(objectUnderTest.getResourceContext()).thenReturn(mockResourceContext);

        Configuration mockConfiguration = mock(Configuration.class);
        when(mockResourceContext.getPluginConfiguration()).thenReturn(mockConfiguration);

        when(mockConfiguration.getSimpleValue(eq("filename"), isNull(String.class))).thenReturn("testFileName");

        File mockFile = mock(File.class);
        PowerMockito.whenNew(File.class).withParameterTypes(String.class).withArguments(any(String.class))
            .thenReturn(mockFile);
        when(mockFile.exists()).thenReturn(true);

        when(mockFile.getName()).thenReturn("testFileName");

        FileContentDelegate mockFileContentDelegate = mock(FileContentDelegate.class);
        PowerMockito.whenNew(FileContentDelegate.class).withArguments(any(File.class), isNull(), isNull())
            .thenReturn(mockFileContentDelegate);
        when(mockFileContentDelegate.getSHA(any(File.class))).thenReturn("abcd1234");

        JarContentFileInfo mockJarContentFileInfo = mock(JarContentFileInfo.class);
        PowerMockito.whenNew(JarContentFileInfo.class).withParameterTypes(File.class).withArguments(any(File.class))
            .thenReturn(mockJarContentFileInfo);
        when(mockJarContentFileInfo.getVersion(isNull(String.class))).thenReturn("testDisplayVersion");

        //create object to test and inject required dependencies
        when(objectUnderTest.discoverDeployedPackages(any(PackageType.class))).thenCallRealMethod();

        //run code under test
        Set<ResourcePackageDetails> result = objectUnderTest.discoverDeployedPackages(mockPackageType);

        //verify the results (Assert and mock verification)
        Assert.assertEquals(result.size(), 1);

        ResourcePackageDetails resultPackageDetails = (ResourcePackageDetails) result.toArray()[0];
View Full Code Here

TOP

Related Classes of org.rhq.plugins.jbossas.ApplicationComponent

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.