Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 50c46446737b7cea88f05d9ad41df9ff9afaf204 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/***************************************************************************
 * Copyright (c) 2004 - 2008 Eike Stepper, Germany.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors:
 *    Eike Stepper - initial API and implementation
 **************************************************************************/
package org.eclipse.emf.cdo.tests.config.impl;

import org.eclipse.emf.cdo.tests.config.IConstants;
import org.eclipse.emf.cdo.tests.config.IScenario;

import java.util.ArrayList;
import java.util.List;

import junit.framework.Test;
import junit.framework.TestResult;
import junit.framework.TestSuite;

/**
 * @author Eike Stepper
 */
public abstract class ConfigTestSuite implements IConstants
{
  public ConfigTestSuite()
  {
  }

  protected Test getTestSuite(String name)
  {
    TestSuite suite = new TestSuite(name);
    initConfigSuites(suite);
    return suite;
  }

  // protected void initConfigSuites(TestSuite parent)
  // {
  // for (ContainerConfig containerConfig : ContainerConfig.CONFIGS)
  // {
  // for (RepositoryConfig repositoryConfig : RepositoryConfig.CONFIGS)
  // {
  // for (SessionConfig sessionConfig : SessionConfig.CONFIGS)
  // {
  // for (ModelConfig modelConfig : ModelConfig.CONFIGS)
  // {
  // initConfigSuite(parent, containerConfig, repositoryConfig, sessionConfig, modelConfig);
  // }
  // }
  // }
  // }
  // }

  protected void addScenario(TestSuite parent, ContainerConfig containerConfig, RepositoryConfig repositoryConfig,
      SessionConfig sessionConfig, ModelConfig modelConfig)
  {
    IScenario scenario = new Scenario();
    scenario.setContainerConfig(containerConfig);
    scenario.setRepositoryConfig(repositoryConfig);
    scenario.setSessionConfig(sessionConfig);
    scenario.setModelConfig(modelConfig);

    if (scenario.isValid())
    {
      TestSuite suite = new TestSuite(scenario.toString());

      List<Class<? extends ConfigTest>> testClasses = new ArrayList<Class<? extends ConfigTest>>();
      initTestClasses(testClasses);

      for (Class<? extends ConfigTest> testClass : testClasses)
      {
        TestWrapper configSuite = new TestWrapper(testClass, scenario);
        suite.addTest(configSuite);
      }

      parent.addTest(suite);
    }
  }

  protected abstract void initConfigSuites(TestSuite parent);

  // protected void initConfigSuites(TestSuite parent)
  // {
  // for (ContainerConfig containerConfig : ContainerConfig.CONFIGS)
  // {
  // for (RepositoryConfig repositoryConfig : RepositoryConfig.CONFIGS)
  // {
  // for (SessionConfig sessionConfig : SessionConfig.CONFIGS)
  // {
  // for (ModelConfig modelConfig : ModelConfig.CONFIGS)
  // {
  // initConfigSuite(parent, containerConfig, repositoryConfig, sessionConfig, modelConfig);
  // }
  // }
  // }
  // }
  // }

  protected abstract void initTestClasses(List<Class<? extends ConfigTest>> testClasses);

  /**
   * @author Eike Stepper
   */
  private static final class TestWrapper extends TestSuite
  {
    private IScenario scenario;

    public TestWrapper(Class<? extends ConfigTest> testClass, IScenario scenario)
    {
      super(testClass, testClass.getName()); // Important for the UI to set the *qualified* class name!
      this.scenario = scenario;
    }

    @Override
    public void runTest(Test test, TestResult result)
    {
      if (test instanceof ConfigTest)
      {
        scenario.save();
        ConfigTest configTest = (ConfigTest)test;
        configTest.setScenario(scenario);
        if (configTest.isValid())
        {
          super.runTest(configTest, result);
        }
      }
      else
      {
        super.runTest(test, result);
      }
    }
  }
}

Back to the top