summaryrefslogtreecommitdiffstats
path: root/sdo-java/trunk-cts/sdo2.1/src/main/java/test/sdo21/tests/api/Sequence/SequenceTest.java
blob: b09d0597f33cef4256cc50620d93d8d5519a8a2a (plain)
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
/*
 *  Licensed to the Apache Software Foundation (ASF) under one
 *  or more contributor license agreements.  See the NOTICE file
 *  distributed with this work for additional information
 *  regarding copyright ownership.  The ASF licenses this file
 *  to you under the Apache License, Version 2.0 (the
 *  "License"); you may not use this file except in compliance
 *  with the License.  You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing,
 *  software distributed under the License is distributed on an
 *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 *  KIND, either express or implied.  See the License for the
 *  specific language governing permissions and limitations
 *  under the License.
 *  
 */
package test.sdo21.tests.api.Sequence;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.*;

import commonj.sdo.DataObject;
import commonj.sdo.Sequence;
import commonj.sdo.Type;
import commonj.sdo.helper.DataFactory;
import commonj.sdo.helper.TypeHelper;

import test.sdo21.framework.CTSTestCase;

/**
 * Set of tests for Sequence APIs.
 */
public class SequenceTest extends CTSTestCase  {

    
    @Before
    public void setUp() throws Exception {
      super.setUp();
    }
    
    @After
    public void tearDown() throws Exception {
      super.tearDown();
    }
    
    /**
     * Test to ensure that once an isMany=false property within a sequenced type
     * retains an existing position in the sequence following an update.
     *@see <A href="http://www.xcalia.com/support/browse/SDO-242">SDO Spec Jira 242</a>
     */
    @Test
    public void testSeqWhenIsManyFalseAndValueUpdated()
    {

      DataFactory df = getScope().getDataFactory();
      TypeHelper th = getScope().getTypeHelper();
      
      Type stringType = th.getType("commonj.sdo", "String");

      DataObject typeModel = df.create("commonj.sdo", "Type");
      typeModel.set("name", "name");
      typeModel.set("uri", "example.org");
      typeModel.set("sequenced", true);
      
      DataObject property1 = typeModel.createDataObject("property");
      property1.set("name", "givenname");
      property1.set("type", stringType);
      
      DataObject property2 = typeModel.createDataObject("property");
      property2.set("name", "familyname");
      property2.set("type", stringType);
      
      th.define(typeModel);
      
      DataObject aName = df.create("example.org", "name");
      
      aName.set("familyname", "Smith");
      aName.set("givenname", "John");
      
      Sequence seq = aName.getSequence();
      // System.out.println(getScope().getXMLHelper().save(aName, "example./org", "aName"));
      
      assertEquals(seq.getValue(0), "Smith");
      assertEquals(seq.getValue(1), "John");
      
      aName.set("familyname", "Jones");
      // System.out.println(getScope().getXMLHelper().save(aName, "example./org", "aName"));
      
      assertEquals(seq.size(), 2);
      
      assertEquals(seq.getValue(0), "Jones");
      assertEquals(seq.getValue(1), "John");
      
    }
}