Package org.jboss.on.plugins.tomcat

Examples of org.jboss.on.plugins.tomcat.TomcatVHostComponent


    @Test
    public void testCreateSource() 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.
        TomcatVHostComponent objectUnderTest = mock(TomcatVHostComponent.class);

        //tell the method story as it happens: mock dependencies and configure
        //those dependencies to get the method under test to completion.
        CreateResourceReport mockCreateResourceReport = mock(CreateResourceReport.class);
        ResourceType mockResourceType = mock(ResourceType.class);
        when(mockCreateResourceReport.getResourceType()).thenReturn(mockResourceType);
        when(mockResourceType.getName()).thenReturn("Tomcat Web Application (WAR)");

        ResourcePackageDetails mockResourcePackageDetails = mock(ResourcePackageDetails.class);
        when(mockCreateResourceReport.getPackageDetails()).thenReturn(mockResourcePackageDetails);
        PackageDetailsKey mockPackageDetailsKey = mock(PackageDetailsKey.class);
        when(mockResourcePackageDetails.getKey()).thenReturn(mockPackageDetailsKey);
        when(mockPackageDetailsKey.getName()).thenReturn("testApplication.war");

        Configuration mockConfiguration = mock(Configuration.class);
        when(mockResourcePackageDetails.getDeploymentTimeConfiguration()).thenReturn(mockConfiguration);
        PropertySimple mockPropertySimple = mock(PropertySimple.class);
        when(mockConfiguration.getSimple(any(String.class))).thenReturn(mockPropertySimple);
        when(mockPropertySimple.getBooleanValue()).thenReturn(Boolean.TRUE);

        EmsBean mockEmsBean = mock(EmsBean.class);
        when(objectUnderTest.getEmsBean()).thenReturn(mockEmsBean);
        EmsAttribute mockEmsAttribute = mock(EmsAttribute.class);
        when(mockEmsBean.getAttribute(anyString())).thenReturn(mockEmsAttribute);
        when(mockEmsAttribute.getValue()).thenReturn(Boolean.TRUE);

        File deploymentDirectory = new File(this.getClass().getResource("/").getFile() + "deploymentDirectory");
        deleteRecursive(deploymentDirectory);
        when(objectUnderTest.getConfigurationPath()).thenReturn(deploymentDirectory);

        File tempDirectory = new File(this.getClass().getResource("/").getFile() + "tempDirectory");
        deleteRecursive(tempDirectory);
        tempDirectory.mkdirs();

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

        ContentContext mockContentContext = mock(ContentContext.class);
        when(mockResourceContext.getContentContext()).thenReturn(mockContentContext);
        ContentServices mockContentServices = mock(ContentServices.class);
        when(mockContentContext.getContentServices()).thenReturn(mockContentServices);

        when(objectUnderTest.isWebApplication(any(File.class))).thenReturn(Boolean.TRUE);

        //run code under test
        when(objectUnderTest.createResource(any(CreateResourceReport.class))).thenCallRealMethod();
        objectUnderTest.createResource(mockCreateResourceReport);

        //verify the results (Assert and mock verification)
        verify(objectUnderTest).getEmsBean();
        verify(objectUnderTest, times(2)).getResourceContext();
        verify(objectUnderTest).getConfigurationPath();
View Full Code Here

TOP

Related Classes of org.jboss.on.plugins.tomcat.TomcatVHostComponent

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.