package org.ovirt.engine.core.utils.ovf;

import java.util.Date;

import org.junit.Assert;
import org.junit.Test;

public class OvfParserTest {

    @Test
    public void UtcDateStringToLocaDate_nodep() {
        Date date =
                OvfParser.UtcDateStringToLocaDate("1984/06/19 14:25:11");
        Assert.assertEquals(456503111000L, date.getTime());
    }

    static class Checker implements Runnable {

        public Checker(String dateStr, long dateVal, long count) {
            super();
            this.dateStr = dateStr;
            this.dateVal = dateVal;
            this.count = count;
        }

        final String dateStr;
        final long dateVal;
        final long count;

        long errors;

        @Override
        public void run() {
            for (long l = 0; l < count; l++) {
                final Date date = OvfParser.UtcDateStringToLocaDate(dateStr);
                if (dateVal != date.getTime()) {
                    errors++;
                }
            }
        }

    }

    @Test
    public void UtcDateStringToLocaDateMultiThread() throws InterruptedException {
        final Thread[] threads = new Thread[8];
        final Checker[] checkers = new Checker[threads.length];
        for (int i = 0; i < threads.length; i++) {
            checkers[i] = new Checker("1984/06/19 14:25:11", 456503111000L, 100000);
            threads[i] = new Thread(checkers[i], "ovf-checker-" + i);
            threads[i].start();
        }

        for (Thread thread : threads) {
            thread.join();
        }

        for (Checker checker : checkers) {
            Assert.assertEquals(checker.errors, 0);
        }
    }

}

@@ -362,1309 +362,6 @@
   %7D%0A
-%0A    static class Checker implements Runnable %7B%0A%0A        public Checker(String dateStr, long dateVal, long count) %7B%0A            super();%0A            this.dateStr = dateStr;%0A            this.dateVal = dateVal;%0A            this.count = count;%0A        %7D%0A%0A        final String dateStr;%0A        final long dateVal;%0A        final long count;%0A%0A        long errors;%0A%0A        @Override%0A        public void run() %7B%0A            for (long l = 0; l %3C count; l++) %7B%0A                final Date date = OvfParser.UtcDateStringToLocaDate(dateStr);%0A                if (dateVal != date.getTime()) %7B%0A                    errors++;%0A                %7D%0A            %7D%0A        %7D%0A%0A    %7D%0A%0A    @Test%0A    public void UtcDateStringToLocaDateMultiThread() throws InterruptedException %7B%0A        final Thread%5B%5D threads = new Thread%5B8%5D;%0A        final Checker%5B%5D checkers = new Checker%5Bthreads.length%5D;%0A        for (int i = 0; i %3C threads.length; i++) %7B%0A            checkers%5Bi%5D = new Checker(%221984/06/19 14:25:11%22, 456503111000L, 100000);%0A            threads%5Bi%5D = new Thread(checkers%5Bi%5D, %22ovf-checker-%22 + i);%0A            threads%5Bi%5D.start();%0A        %7D%0A%0A        for (Thread thread : threads) %7B%0A            thread.join();%0A        %7D%0A%0A        for (Checker checker : checkers) %7B%0A            Assert.assertEquals(checker.errors, 0);%0A        %7D%0A    %7D%0A%0A
 %7D%0A

remove UtcDateStringToLocaDateMultiThread