Commit 5421b845 authored by Michael Suzuki's avatar Michael Suzuki
Browse files

seperated tests into unit and integration

parent fc557164
Loading
Loading
Loading
Loading
+6 −1
Original line number Diff line number Diff line
Message: ${message}
 No newline at end of file
<html>
    <body>
        <h1 id="demo-title">Welcome to Demoamp</h1>
        <p id="demo-message">${demoMessage}</p>
    </body>
</html>
 No newline at end of file
+29 −0
Original line number Diff line number Diff line
@@ -15,7 +15,18 @@
	limitations under the License.
 */
package org.alfresco.demoamp;
import java.util.HashMap;
import java.util.Map;

import org.alfresco.model.ContentModel;
import org.alfresco.repo.nodelocator.NodeLocatorService;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.extensions.webscripts.DeclarativeWebScript;
import org.springframework.extensions.webscripts.Status;
import org.springframework.extensions.webscripts.WebScriptRequest;
import org.alfresco.repo.module.AbstractModuleComponent;
import org.alfresco.repo.nodelocator.NodeLocatorService;
import org.alfresco.service.cmr.repository.NodeRef;
@@ -23,6 +34,7 @@ import org.alfresco.service.cmr.repository.NodeService;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;


/**
 * A basic component that will be started for this module.
 * Uses the NodeLocatorService to easily find nodes and the 
@@ -30,6 +42,7 @@ import org.apache.commons.logging.LogFactory;
 * 
 * @author Gabriele Columbro
 * @author Maurizio Pillitu
 * @author Michael Suzuki
 */
public class DemoComponent extends AbstractModuleComponent
{
@@ -81,4 +94,20 @@ public class DemoComponent extends AbstractModuleComponent
    {
        return nodeLocatorService.getNode("companyhome", null, null);
    }
    /**
     * Binding data to webscript demoamp. 
     * @param req webscript request
     * @param status 
     * @return {@link java.util.Map} data binding
     */
    protected Map<String, Object> executeImpl(WebScriptRequest req, Status status )
    {
        NodeRef companyHome = getCompanyHome();
        String companyHomeName = (String) nodeService.getProperty(companyHome, ContentModel.PROP_NAME);
        int directoryCount = childNodesCount(companyHome);
        HelloWorldMessage msg = new HelloWorldMessage(companyHomeName, directoryCount);
        Map<String, Object> model = new HashMap<String, Object>();
        model.put("demoMessage", msg);
        return model;
    }
}
+58 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2005-2007 Alfresco Software Limited.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 * As a special exception to the terms and conditions of version 2.0 of 
 * the GPL, you may redistribute this Program in connection with Free/Libre 
 * and Open Source Software ("FLOSS") applications as described in Alfresco's 
 * FLOSS exception.  You should have recieved a copy of the text describing 
 * the FLOSS exception, and it is also available here: 
 * http://www.alfresco.com/legal/licensing"
 */
package org.alfresco.demoamp;

import com.sun.star.uno.RuntimeException;

/**
 * Simple pojo that holds directory name and 
 * the number of folders in the directory.
 * 
 * This is used to create the message for the demoamp.
 * 
 * @author Michael Suzuki
 *
 */
public class HelloWorldMessage
{
    private final String directoryName;
    private final int folders;
    
    public HelloWorldMessage(final String directoryName, final int folders)
    {
        if(directoryName == null || directoryName.isEmpty())
        {
            throw new RuntimeException("Directory name is required");
        }
        this.directoryName = directoryName;
        this.folders = folders;
    }
    
    public String toString()
    {
        return String.format("%s has %d folders", directoryName, folders);
    }
    
}
+0 −0

File moved.

+50 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2005-2012 Alfresco Software Limited.
 * This file is part of Alfresco
 * Alfresco is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * Alfresco is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Lesser General Public License for more details.
 * You should have received a copy of the GNU Lesser General Public License
 * along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
 */
package org.alfresco.demo.test.unit;

import org.alfresco.demoamp.HelloWorldMessage;
import org.junit.Assert;
import org.junit.Test;


/**s
 * Hello world demo unit test, show the basics of junit and unit testing.
 * Create the message to display on hello world webscript.
 * @author Michael Suzuki
 *
 */
public class HelloWorldMessageTest
{
    @Test
    public void init()
    {
        HelloWorldMessage msg = new HelloWorldMessage("bla", 0);
        Assert.assertNotNull(msg);
    }
    
    @Test(expected = RuntimeException.class)
    public void initWithNull()
    {
        new HelloWorldMessage(null, 0);
    }
    @Test
    public void toStringTest()
    {
        HelloWorldMessage msg = new HelloWorldMessage("Home", 10);
        Assert.assertNotNull(msg);
        Assert.assertEquals("Home has 10 folders",msg.toString());
    }
    
}