Package com.darkhonor.rage.model

Examples of com.darkhonor.rage.model.TestCase


    }
   
    @Test
    public void testCreateNoExcludes()
    {
        TestCase testCase = createNewTestCaseNoExcludes();
        assertTrue(instance.isOpen());
        Long result = instance.create(testCase);
        assertTrue(instance.isOpen());
        assertEquals(new Long(42L), result);
        TestCase searchTestCase = instance.find(new Long(42L));
        assertNotNull(searchTestCase);
        assertEquals(new BigDecimal("10.24"), searchTestCase.getValue());
        assertEquals(2, searchTestCase.getInputs().size());
        assertEquals("12", searchTestCase.getInputs().get(0));
        assertEquals("34", searchTestCase.getInputs().get(1));
        assertEquals(1, searchTestCase.getOutputs().size());
        assertEquals("56", searchTestCase.getOutputs().get(0));
        assertEquals(0, searchTestCase.getExcludes().size());  
    }
View Full Code Here


    }
   
    @Test
    public void testCreateNoInputs()
    {
        TestCase testCase = createNewTestCaseNoInputs();
        assertTrue(instance.isOpen());
        Long result = instance.create(testCase);
        assertTrue(instance.isOpen());
        assertEquals(new Long(45L), result);
        TestCase searchTestCase = instance.find(new Long(45L));
        assertNotNull(searchTestCase);
        assertEquals(new BigDecimal("10.25"), searchTestCase.getValue());
        assertEquals(0, searchTestCase.getInputs().size());
        assertEquals(1, searchTestCase.getOutputs().size());
        assertEquals("Hello World", searchTestCase.getOutputs().get(0));
        assertEquals(0, searchTestCase.getExcludes().size());
    }
View Full Code Here

   
    @Test
    public void testCreateNoId()
    {
        System.out.println("create - No Id");
        TestCase testCase = createNewTestCaseNoId();
        assertTrue(instance.isOpen());
        Long result = instance.create(testCase);
        assertTrue(instance.isOpen());
        TestCase searchTestCase = instance.find(result);
        assertNotNull(searchTestCase);
        assertEquals(new BigDecimal("10.18"), searchTestCase.getValue());
        assertEquals(2, searchTestCase.getInputs().size());
        assertEquals("12", searchTestCase.getInputs().get(0));
        assertEquals("34", searchTestCase.getInputs().get(1));
        assertEquals(1, searchTestCase.getOutputs().size());
        assertEquals("56", searchTestCase.getOutputs().get(0));
        assertEquals(0, searchTestCase.getExcludes().size());
    }
View Full Code Here

            // Run all test cases for the question
            Iterator testCaseIterator = question.getTestCases().iterator();
            while (testCaseIterator.hasNext())
            {
                TestCase testCase = (TestCase) testCaseIterator.next();

                // Create temp files with response information from the database
                File tempIn = File.createTempFile("rage", ".tmp");
                File tempOut = File.createTempFile("rage", ".tmp");

                FileOutputStream outFile = new FileOutputStream(tempIn);
                FileChannel outChannel = outFile.getChannel();
                outChannel.lock();
                for (int i = 0; i < testCase.getInputs().size(); i++)
                {
                    buffer.put(testCase.getInputs().get(i).getBytes());
                    buffer.put(System.getProperty("line.separator").getBytes());
                    buffer.flip();
                    outChannel.write(buffer);
                    buffer.clear();
                }
                outFile.close();
                outChannel.close();

                List<String> cmd = new ArrayList<String>();
                if (type == RAGEConst.RAPTOR_QUESTION// It's a RAPTOR algorithm
                {
                    cmd.add(node.get("RaptorExecutable",
                            RAGEConst.DEFAULT_RAPTOR_EXECUTABLE));
                    cmd.add("\"" + testFile.getCanonicalPath() + "\"");
                    cmd.add("/run");
                    cmd.add("\"" + tempIn.getCanonicalPath() + "\"");
                    cmd.add("\"" + tempOut.getCanonicalPath() + "\"");
                } else if (type == RAGEConst.PROCESSING_QUESTION)    // It's a Processing sketch
                {
                    // TODO: Change from runme to full native Java call
                    cmd.add(node.get("RunmeExecutable",
                            RAGEConst.DEFAULT_PROCESSING_RUNNER));
                    cmd.add(question.getName());
                    for (int i = 0; i < testCase.getInputs().size(); i++)
                    {
                        cmd.add(testCase.getInputs().get(i));
                    }
                    cmd.add(">" + tempOut.getCanonicalPath());

                } else
                {
                    LOGGER.error("Unsupported Question Type");
                    throw new UnsupportedOperationException();
                }
                LOGGER.debug("Command: " + cmd);
                processBuilder.command(cmd);

                // Add thread protection
                Process p = processBuilder.start();
                Long startTimeInNanoSec = System.nanoTime();
                Long delayInNanoSec;

                // If Inifinite Loop protection is enabled, default to true
                if (node.getBoolean("InfiniteLoopDetection", true))
                {
                    LOGGER.debug("Infinite loop detection is enabled");
                    try
                    {
                        delayInNanoSec =
                                Long.parseLong(node.get("Threshold", "10")) * 1000000000;
                    } catch (NumberFormatException e)
                    {
                        LOGGER.warn("Invalid Threshold value.  Defaulting to 10");
                        delayInNanoSec = new Long(10 * 1000000000);
                    }
                    boolean timeFlag = true;
                    while (timeFlag)
                    {
                        try
                        {
                            int val = p.exitValue();
                            timeFlag = false;
                        } // This should come back with an exception
                        // if the process is still going
                        catch (IllegalThreadStateException e)
                        {
                            Long elapsedTime = System.nanoTime()
                                    - startTimeInNanoSec;
                            if (elapsedTime > delayInNanoSec)
                            {
                                LOGGER.warn("Threshold time exceeded.");
                                p.destroy();
                                timeFlag = false;
                            }
                            Thread.sleep(50);
                        }
                    }
                } else
                {
                    LOGGER.debug("Infinite loop detection is not enabled");
                    p.waitFor();
                }

                File newTemp = null;
                BufferedReader inFile;
                // Read the results from the user and store
                try
                {
                    inFile = new BufferedReader(new FileReader(tempOut));
                } catch (FileNotFoundException ex)
                {   /* Assume since the file is locked by another process
                     * that no good output is available...come up with a
                     * dummy file to pass to the grader.
                     */
                    LOGGER.error("The file is in use by another process.");
                    newTemp = File.createTempFile("rage", ".tmp");
                    inFile = new BufferedReader(new FileReader(newTemp));
                }
                String line = null;
                while ((line = inFile.readLine()) != null)
                {
                    // Add to list of output for the TestCase
                    testCase.addOutput(line);
                }
                inFile.close();
                tempIn.delete();
                tempOut.delete();
                if (newTemp != null)
View Full Code Here

   
    @Test(expected = IllegalStateException.class)
    public void testCreateClosedConnection()
    {
        System.out.println("create - Closed Connection");
        TestCase testCase = createNewTestCase();
        assertTrue(instance.isOpen());
        instance.closeConnection();
        assertFalse(instance.isOpen());
        Long result = instance.create(testCase);
    }
View Full Code Here

   
    @Test(expected = NullPointerException.class)
    public void testCreateNullTestCase()
    {
        System.out.println("create - null TestCase");
        TestCase testCase = null;
        assertTrue(instance.isOpen());
        Long result = instance.create(testCase);
    }
View Full Code Here

   
    @Test(expected = IllegalArgumentException.class)
    public void testCreateNullTestCaseValue()
    {
        System.out.println("create - null TestCase Value");
        TestCase testCase = new TestCase();
        testCase.setId(new Long(42L));
        testCase.addInput("12");
        testCase.addInput("34");
        testCase.addOutput("56");
        assertTrue(instance.isOpen());
        Long result = instance.create(testCase);
    }
View Full Code Here

   
    @Test(expected = IllegalArgumentException.class)
    public void testCreateDuplicate()
    {
        System.out.println("create - Duplicate TestCase");
        TestCase testCase = createSampleTestCase1();
        assertTrue(instance.isOpen());
        Long result = instance.create(testCase);
    }
View Full Code Here

     */
    @Test
    public void testUpdate()
    {
        System.out.println("update");
        TestCase testCase = createSampleTestCase1();
        assertTrue(instance.isOpen());
       
        testCase.setValue(new BigDecimal("1.6"));
        testCase.addInput("9876");
        testCase.setOutputs(new ArrayList<String>());
        testCase.addOutput("Name - Bigfellar");
        testCase.addOutput("Race - Tauren");
        testCase.addExclusion("Orc");
        testCase.addExclusion("Human");
              
        TestCase result = instance.update(testCase);
        assertTrue(instance.isOpen());

        assertNotNull(result);
        assertNotNull(result.getId());
        assertEquals(new Long(5L), result.getId());
        assertNotNull(result.getValue());
        assertEquals(new BigDecimal("1.6"), result.getValue());
        assertNotNull(result.getInputs());
        assertEquals(3, result.getInputs().size());
        assertEquals("1234", result.getInputs().get(0));
        assertEquals("5678", result.getInputs().get(1));
        assertEquals("9876", result.getInputs().get(2));
        assertNotNull(result.getOutputs());
        assertEquals(2, result.getOutputs().size());
        assertEquals("Name - Bigfellar", result.getOutputs().get(0));
        assertEquals("Race - Tauren", result.getOutputs().get(1));
        assertNotNull(result.getExcludes());
        assertEquals(5, result.getExcludes().size());
        assertEquals("2345", result.getExcludes().get(0));
        assertEquals("9876", result.getExcludes().get(1));
        assertEquals("Result = 12345678", result.getExcludes().get(2));
        assertEquals("Orc", result.getExcludes().get(3));
        assertEquals("Human", result.getExcludes().get(4));
    }
View Full Code Here

    @Test
    public void testUpdateNoInputs()
    {
        System.out.println("update - To no Inputs");
        TestCase testCase = createSampleTestCase1();
        assertTrue(instance.isOpen());
       
        testCase.setValue(new BigDecimal("1.6"));
        testCase.setInputs(new ArrayList<String>());
        testCase.setOutputs(new ArrayList<String>());
        testCase.addOutput("Name - Bigfellar");
        testCase.addOutput("Race - Tauren");
        testCase.addExclusion("Orc");
        testCase.addExclusion("Human");
              
        TestCase result = instance.update(testCase);
        assertTrue(instance.isOpen());

        assertNotNull(result);
        assertNotNull(result.getId());
        assertEquals(new Long(5L), result.getId());
        assertNotNull(result.getValue());
        assertEquals(new BigDecimal("1.6"), result.getValue());
        assertNotNull(result.getInputs());
        assertEquals(0, result.getInputs().size());
        assertNotNull(result.getOutputs());
        assertEquals(2, result.getOutputs().size());
        assertEquals("Name - Bigfellar", result.getOutputs().get(0));
        assertEquals("Race - Tauren", result.getOutputs().get(1));
        assertNotNull(result.getExcludes());
        assertEquals(5, result.getExcludes().size());
        assertEquals("2345", result.getExcludes().get(0));
        assertEquals("9876", result.getExcludes().get(1));
        assertEquals("Result = 12345678", result.getExcludes().get(2));
    }
View Full Code Here

TOP

Related Classes of com.darkhonor.rage.model.TestCase

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.