Skip to main content
summaryrefslogtreecommitdiffstats
blob: 25d5f73ea6825988aa3e7c5271a099e0422e9228 (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
136
137
138
139
/*******************************************************************************
 * Copyright (c) 2002-2005 IBM Corporation and others.
 * 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:
 *   IBM - Initial API and implementation
 *******************************************************************************/
package org.eclipse.wst.wsi.tests.internal;

import java.util.List;

import org.eclipse.wst.wsi.internal.WSIPreferences;
import org.eclipse.wst.wsi.internal.WSITestToolsProperties;
import org.eclipse.wst.wsi.internal.analyzer.MessageAnalyzer;

public class CoreMessageLogConformanceTest extends CoreConformanceTest 
{
  public static final String MESSAGE_LOG_BASE_DIRECTORY =
      "testResources/samples/messageLogs";
  public static final String MESSAGE_LOG_EXTENSION = ".wsimsg";
  public static final String WSDL_BASE_DIRECTORY = "testResources/samples/wsdl";
  public static final String WSDL_EXTENSION = ".wsdl";

  public CoreMessageLogConformanceTest(String name) 
  {
      super(name);
  }

  /**
   * JUnit test: validate the message log against the specified WS-I Profile.
   * @param tad he WS-I Test Assertion Document
   * @param testName the name of the test containing the wsdl document
   */
  protected void runTest(String category, String testName, String tadID) {	
      this.tadID = tadID;

      assertNotNull("Problems determining base url", pluginURI);
      String testDirectory  = pluginURI + MESSAGE_LOG_BASE_DIRECTORY + "/" +
              category + "/" + testName;
      String messageLogFile = "file://" + testDirectory + "/" + testName +
              MESSAGE_LOG_EXTENSION;
      String testcaseFile = testDirectory +  "/" + TEST_CASE_FILE;

      // validate the message log document
      MessageAnalyzer analyzer = validateConformance(messageLogFile, tadID);
      assertNotNull("Unknown problems during validation", analyzer);

      // retrieve the expected assertion failures
      List expectedErrors = getExpectedAssertionFailures(testcaseFile);
      assertNotNull("Problems retrieving expected failures", expectedErrors);

      // compare the actual errors with the expected errors
      analyzeResults(analyzer.getAssertionErrors(), expectedErrors);
  }

  /**
   * Validate the wsdl document against the specified WS-I Profile.
   * @param tad  the WS-I Test Assertion Document
   * @param filename the wsdl document
   * @return the WSDLAnalyzer object containing the validation results
   */  
  protected MessageAnalyzer validateConformance(String filename, String tadID) {
      MessageAnalyzer analyzer = null;
      try {
          WSIPreferences preferences = new WSIPreferences();
          preferences.setComplianceLevel( WSITestToolsProperties.STOP_NON_WSI);
          preferences.setTADFile(getTADURI(tadID));

          analyzer = new MessageAnalyzer(filename, preferences);

          // run the conformance check and add errors and warnings as needed
          analyzer.validateConformance();
      } catch (Exception e) {
          return null;
      }	
      return analyzer;
  }

  
  
  /**
   * JUnit test: validate the message log with a WSDL file
   * @param wsdlFile URI of the WSDL file
   * @param WSData String array containing: elementname, namespace, parentname, type
   * @param filename the name of the log and wsdl file (they should be located in the log and wsdl paths respectively)
   */
  
  protected void runTestWithWSDL(String category, String testName, String[] WSData) {	

      assertNotNull("Problems determining base url", pluginURI);
      String testDirectory  = pluginURI + MESSAGE_LOG_BASE_DIRECTORY + "/" +
              category + "/" + testName;
      String messageLogFile = "file://" + testDirectory + "/" + testName +
              MESSAGE_LOG_EXTENSION;
      String testcaseFile = testDirectory +  "/" + TEST_CASE_FILE;
      String wsdlFile = "file://" + pluginURI + WSDL_BASE_DIRECTORY + "/" + category + "/" + testName + WSDL_EXTENSION;
      
      // validate the message log document
      MessageAnalyzer analyzer = validateConformanceWithWSDL(messageLogFile, wsdlFile, WSData);
      assertNotNull("Unknown problems during validation", analyzer);

      // retrieve the expected assertion failures
      List expectedErrors = getExpectedAssertionFailures(testcaseFile);
      assertNotNull("Problems retrieving expected failures", expectedErrors);

      // compare the actual errors with the expected errors
      analyzeResults(analyzer.getAssertionErrors(), expectedErrors);
  }


  /**
   * Validate log with a WSDL file
   * @param wsdlFile URI of the WSDL file
   * @param WSData String array containing: elementname, namespace, parentname, type
   * @param filename the name of the log and wsdl file (they should be located in the log and wsdl paths respectively)
   * @return the WSDLAnalyzer object containing the validation results
   */  

	protected MessageAnalyzer validateConformanceWithWSDL(String filename, String wsdlFile, String[] WSData) {
	    MessageAnalyzer analyzer = null;
	    try {
	        WSIPreferences preferences = new WSIPreferences();
	        preferences.setComplianceLevel( WSITestToolsProperties.STOP_NON_WSI);
	        preferences.setTADFile(getTADURI(tadID));
	
	        analyzer = new MessageAnalyzer(filename, wsdlFile, WSData[0],  WSData[1], WSData[2], WSData[3], preferences);
	
	        // run the conformance check and add errors and warnings as needed
	        analyzer.validateConformance();
	    } catch (Exception e) {
	        return null;
	    }	
	    return analyzer;
	}

}

Back to the top