Skip to main content
summaryrefslogtreecommitdiffstats
blob: 9c861a3b4f293d1e8b5c3089a548cddc49cca47c (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
/*******************************************************************************
 * Copyright (c) 2006 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 Corporation - initial API and implementation
 *******************************************************************************/

package org.eclipse.wst.wsdl.tests;

import java.util.List;

import junit.framework.Assert;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;

import org.eclipse.wst.wsdl.Definition;
import org.eclipse.wst.wsdl.Service;
import org.eclipse.wst.wsdl.Types;
import org.eclipse.wst.wsdl.XSDSchemaExtensibilityElement;
import org.eclipse.wst.wsdl.tests.util.DefinitionLoader;
import org.eclipse.wst.wsdl.util.WSDLParser;
import org.eclipse.wst.wsdl.util.WSDLResourceImpl;
import org.eclipse.xsd.XSDElementDeclaration;
import org.eclipse.xsd.XSDSchema;
import org.eclipse.xsd.util.XSDParser;
import org.w3c.dom.Element;

/**
 * Test class used to validate the WSDL model source location tracking
 * mechanism.
 */
public class LocationTrackingTest extends TestCase
{

  public static Test suite()
  {
    TestSuite suite = new TestSuite();
    suite.addTest(new LocationTrackingTest()
    {
      protected void runTest()
      {
        testTracksLocation();
      }
    });
    return suite;
  }

  /**
   * Tests the location tracking mechanism provided by the WSDL model resource
   * loader.
   * 
   * @see WSDLResourceImpl
   * @see WSDLParser
   */
  public void testTracksLocation()
  {
    try
    {
      String fileName = WSDLTestsPlugin.getInstallURL() + "/samples/LoadAndPrintTest.wsdl"; //$NON-NLS-1$
      Definition definition = DefinitionLoader.load(fileName, true, true);
      Assert.assertNotNull(definition);
      Assert.assertTrue(definition.eResource() instanceof WSDLResourceImpl);

      Element definitionElement = definition.getElement();
      assertEquals(1, WSDLParser.getStartLine(definitionElement));

      Types types = definition.getETypes();
      Element typesElement = types.getElement();
      assertEquals(4, WSDLParser.getStartLine(typesElement));

      List typesExtensibilityElements = types.getEExtensibilityElements();

      assertEquals(1, typesExtensibilityElements.size());

      XSDSchemaExtensibilityElement schemaExtension = (XSDSchemaExtensibilityElement) typesExtensibilityElements.get(0);

      XSDSchema schema = schemaExtension.getSchema();

      Element schemaElement = schema.getElement();

      assertEquals(5, XSDParser.getStartLine(schemaElement));

      XSDElementDeclaration requestElementDeclaration = schema.resolveElementDeclaration("NewOperationRequest"); //$NON-NLS-1$

      Element requestElement = requestElementDeclaration.getElement();

      assertEquals(7, XSDParser.getStartLine(requestElement));

      List services = definition.getEServices();
      assertEquals(1, services.size());
      Service service = (Service) services.get(0);

      Element serviceElement = service.getElement();
      assertEquals(42, WSDLParser.getStartLine(serviceElement));
    }
    catch (Exception e)
    {
      Assert.fail("Test failed due to an exception: " + e.getLocalizedMessage());
    }
  }
}

Back to the top