package com.ibtp.kontor.dal;

import static org.junit.jupiter.api.Assertions.fail;

import java.lang.reflect.Method;

import org.junit.jupiter.api.Test;

/**
 * Created by TPEETZ on 10.02.2015.
 */
public class DataAccessLayerTest {

    public void findTests(String packageName, String entityName) {
        String testClassName = packageName + entityName + "ImplTest";
        Class testClass;
        try {
            testClass = Class.forName(testClassName);
            Method addAndDelete = testClass.getMethod("test" + entityName + "AddAndDelete");
            Method findAll = testClass.getMethod("test" + entityName + "FindAll");
        } catch (ClassNotFoundException e) {
            fail("Class " + testClassName + " missing");
        } catch (NoSuchMethodException e) {
            fail("Test method for class " + testClassName + " missing");
        }
    }

    @Test
    public void testFindComicTests() {
        /*
         * Find all Tests
         */
        String[] testClasses = new String[]{"Artist", "Comic", "Issue", "Publisher", "StoryArc", "Volume"};
        for (int i = 0; i < testClasses.length; i++) {
            String testEntity = testClasses[i];
            findTests("com.ibtp.kontor.comics.dal.", testEntity);
        }
    }

    @Test
    public void testFindLibraryTests() {
        /*
         * Find all Tests
         */
        String[] testClasses = new String[]{"Article", "Author", "Book", "File", "Title"};
        for (int i = 0; i < testClasses.length; i++) {
            String testEntity = testClasses[i];
            findTests("com.ibtp.kontor.library.dal.", testEntity);
        }
    }

    @Test
    public void testFindTradingCardsTests() {
        /*
         * Find all Tests
         */
        String[] testClasses = new String[]{"BaseSet", "Insert", "Manufacturer", "ParallelSet", "Player", "Position", "SportCard", "Sport", "Team"};
        for (int i = 0; i < testClasses.length; i++) {
            String testEntity = testClasses[i];
            findTests("com.ibtp.kontor.tradingcards.dal." , testEntity);
        }
    }
}
