Package org.spw.controller

Source Code of org.spw.controller.DocumentControllerTest

/*
* DocumentControllerTest.java
* JUnit based test
*
* Created on 17 August 2007, 18:30
*/

package org.spw.controller;

import junit.framework.*;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import javax.persistence.Query;
import org.spw.model.Document;

/**
*
* @author PSe
*/
public class DocumentControllerTest extends TestCase {
    private static final long TEST_ID = 9999999L;
    private static final DocumentController ctrl = new DocumentController();
   
    public DocumentControllerTest(String testName) {
        super(testName);
    }

    protected void setUp() throws Exception {
        Document docTest = new Document();
        docTest.setIdDocument(TEST_ID);
        docTest.setDocumentLink(getName());
        docTest.setTitle(getName());
        docTest.setDocumentType("Fax");
        ctrl.create(docTest);
    }

    protected void tearDown() throws Exception {
        ctrl.delete(ctrl.read(TEST_ID));
    }

    /**
     * Test of getDocuments method, of class org.spw.controller.DocumentController.
     */
    public void testGetDocuments() {
        boolean found = false;
        System.out.println("getDocuments");
       
        List<Document> result = ctrl.getDocuments();
        assertNotNull(result);
        assertTrue(result.size() > 0);
        for (Document doc : result) {
            if (doc.getIdDocument() == TEST_ID) {
                found = true;
                break;
            }
        }
        assertTrue("Cannot find the test entity.", found);
    }

    /**
     * Test of parse method, of class org.spw.controller.DocumentController.
     */
    public void testParse() {
        System.out.println("parse");
       
        String id = "";
       
        Document result = ctrl.parse(id);
        assertNull("Must not find a document with incorrect string rep.", result);
        id = null;
        assertNull("Must not find a document with incorrect string rep.", result);
        id = "]9999999[";
        assertNull("Must not find a document with incorrect string rep.", result);
       
        id = "anything[9999999]";
        result = ctrl.parse(id);
        assertEquals((long)TEST_ID, (long)result.getIdDocument());
    }
   
}
TOP

Related Classes of org.spw.controller.DocumentControllerTest

TOP
Copyright © 2018 www.massapi.com. 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.