/php/php.doctrine2/test/unit/src/org/netbeans/modules/php/doctrine2/annotations/orm/parser/JoinTableLineParserTest.java

https://github.com/apache/incubator-netbeans · Java · 201 lines · 157 code · 22 blank · 22 comment · 0 complexity · 0e91324ab93111fb830119dbdb20d7f1 MD5 · raw file

  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing,
  13. * software distributed under the License is distributed on an
  14. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  15. * KIND, either express or implied. See the License for the
  16. * specific language governing permissions and limitations
  17. * under the License.
  18. */
  19. package org.netbeans.modules.php.doctrine2.annotations.orm.parser;
  20. import java.util.Map;
  21. import org.netbeans.junit.NbTestCase;
  22. import org.netbeans.modules.csl.api.OffsetRange;
  23. import org.netbeans.modules.php.spi.annotation.AnnotationLineParser;
  24. import org.netbeans.modules.php.spi.annotation.AnnotationParsedLine;
  25. /**
  26. *
  27. * @author Ondrej Brejla <obrejla@netbeans.org>
  28. */
  29. public class JoinTableLineParserTest extends NbTestCase {
  30. private EncapsulatingAnnotationLineParser parser;
  31. public JoinTableLineParserTest(String name) {
  32. super(name);
  33. }
  34. @Override
  35. protected void setUp() throws Exception {
  36. super.setUp();
  37. this.parser = new EncapsulatingAnnotationLineParser();
  38. }
  39. public void testIsAnnotationParser() throws Exception {
  40. assertTrue(parser instanceof AnnotationLineParser);
  41. }
  42. public void testReturnValueIsJoinTableParsedLine_01() throws Exception {
  43. assertTrue(parser.parse("JoinTable") instanceof AnnotationParsedLine.ParsedLine);
  44. }
  45. public void testReturnValueIsJoinTableParsedLine_02() throws Exception {
  46. assertTrue(parser.parse("Annotations\\JoinTable") instanceof AnnotationParsedLine.ParsedLine);
  47. }
  48. public void testReturnValueIsJoinTableParsedLine_03() throws Exception {
  49. assertTrue(parser.parse("\\Foo\\Bar\\JoinTable") instanceof AnnotationParsedLine.ParsedLine);
  50. }
  51. public void testReturnValueIsJoinTableParsedLine_04() throws Exception {
  52. assertTrue(parser.parse("Annotations\\JoinTable(name=\"user\")") instanceof AnnotationParsedLine.ParsedLine);
  53. }
  54. public void testReturnValueIsNull() throws Exception {
  55. assertNull(parser.parse("JoinTables"));
  56. }
  57. public void testValidUseCase_01() throws Exception {
  58. AnnotationParsedLine parsedLine = parser.parse("JoinTable");
  59. assertEquals("JoinTable", parsedLine.getName());
  60. assertEquals("", parsedLine.getDescription());
  61. Map<OffsetRange, String> types = parsedLine.getTypes();
  62. assertNotNull(types);
  63. assertEquals(1, types.size());
  64. String type1 = types.get(new OffsetRange(0, 9));
  65. assertEquals("JoinTable", type1);
  66. }
  67. public void testValidUseCase_02() throws Exception {
  68. AnnotationParsedLine parsedLine = parser.parse("JoinTable ");
  69. assertEquals("JoinTable", parsedLine.getName());
  70. assertEquals("", parsedLine.getDescription());
  71. Map<OffsetRange, String> types = parsedLine.getTypes();
  72. assertNotNull(types);
  73. assertEquals(1, types.size());
  74. String type1 = types.get(new OffsetRange(0, 9));
  75. assertEquals("JoinTable", type1);
  76. }
  77. public void testValidUseCase_03() throws Exception {
  78. AnnotationParsedLine parsedLine = parser.parse("JoinTable\t\t ");
  79. assertEquals("JoinTable", parsedLine.getName());
  80. assertEquals("", parsedLine.getDescription());
  81. Map<OffsetRange, String> types = parsedLine.getTypes();
  82. assertNotNull(types);
  83. assertEquals(1, types.size());
  84. String type1 = types.get(new OffsetRange(0, 9));
  85. assertEquals("JoinTable", type1);
  86. }
  87. public void testValidUseCase_04() throws Exception {
  88. AnnotationParsedLine parsedLine = parser.parse("JoinTable(name=\"user\")");
  89. assertEquals("JoinTable", parsedLine.getName());
  90. assertEquals("(name=\"user\")", parsedLine.getDescription());
  91. Map<OffsetRange, String> types = parsedLine.getTypes();
  92. assertNotNull(types);
  93. assertEquals(1, types.size());
  94. String type1 = types.get(new OffsetRange(0, 9));
  95. assertEquals("JoinTable", type1);
  96. }
  97. public void testValidUseCase_05() throws Exception {
  98. AnnotationParsedLine parsedLine = parser.parse("Annotations\\JoinTable(name=\"user\") \t");
  99. assertEquals("JoinTable", parsedLine.getName());
  100. assertEquals("(name=\"user\")", parsedLine.getDescription());
  101. Map<OffsetRange, String> types = parsedLine.getTypes();
  102. assertNotNull(types);
  103. assertEquals(1, types.size());
  104. String type1 = types.get(new OffsetRange(0, 21));
  105. assertEquals("Annotations\\JoinTable", type1);
  106. }
  107. public void testValidUseCase_06() throws Exception {
  108. AnnotationParsedLine parsedLine = parser.parse("\\Foo\\Bar\\JoinTable(name=\"user\") \t");
  109. assertEquals("JoinTable", parsedLine.getName());
  110. assertEquals("(name=\"user\")", parsedLine.getDescription());
  111. Map<OffsetRange, String> types = parsedLine.getTypes();
  112. assertNotNull(types);
  113. assertEquals(1, types.size());
  114. String type1 = types.get(new OffsetRange(0, 18));
  115. assertEquals("\\Foo\\Bar\\JoinTable", type1);
  116. }
  117. public void testValidUseCase_07() throws Exception {
  118. AnnotationParsedLine parsedLine = parser.parse("jointable");
  119. assertEquals("JoinTable", parsedLine.getName());
  120. assertEquals("", parsedLine.getDescription());
  121. Map<OffsetRange, String> types = parsedLine.getTypes();
  122. assertNotNull(types);
  123. assertEquals(1, types.size());
  124. String type1 = types.get(new OffsetRange(0, 9));
  125. assertEquals("jointable", type1);
  126. }
  127. public void testValidUseCase_08() throws Exception {
  128. AnnotationParsedLine parsedLine = parser.parse("\\Foo\\Bar\\jointable(name=\"user\") \t");
  129. assertEquals("JoinTable", parsedLine.getName());
  130. assertEquals("(name=\"user\")", parsedLine.getDescription());
  131. Map<OffsetRange, String> types = parsedLine.getTypes();
  132. assertNotNull(types);
  133. assertEquals(1, types.size());
  134. String type1 = types.get(new OffsetRange(0, 18));
  135. assertEquals("\\Foo\\Bar\\jointable", type1);
  136. }
  137. public void testValidUseCase_09() throws Exception {
  138. AnnotationParsedLine parsedLine = parser.parse("\\Foo\\Bar\\JoinTable(name=\"users_phonenumbers\", joinColumns={@JoinColumn(name=\"user_id\", referencedColumnName=\"id\")}, inverseJoinColumns={@JoinColumn(name=\"phonenumber_id\", referencedColumnName=\"id\", unique=true)})");
  139. assertEquals("JoinTable", parsedLine.getName());
  140. assertEquals("(name=\"users_phonenumbers\", joinColumns={@JoinColumn(name=\"user_id\", referencedColumnName=\"id\")}, inverseJoinColumns={@JoinColumn(name=\"phonenumber_id\", referencedColumnName=\"id\", unique=true)})", parsedLine.getDescription());
  141. Map<OffsetRange, String> types = parsedLine.getTypes();
  142. assertNotNull(types);
  143. assertEquals(3, types.size());
  144. String type1 = types.get(new OffsetRange(0, 18));
  145. assertEquals("\\Foo\\Bar\\JoinTable", type1);
  146. String type2 = types.get(new OffsetRange(60, 70));
  147. assertEquals("JoinColumn", type2);
  148. String type3 = types.get(new OffsetRange(137, 147));
  149. assertEquals("JoinColumn", type3);
  150. }
  151. public void testValidUseCase_10() throws Exception {
  152. AnnotationParsedLine parsedLine = parser.parse("\\Foo\\Bar\\jointable(name=\"users_phonenumbers\", joinColumns={@joincolumn(name=\"user_id\", referencedColumnName=\"id\")}, inverseJoinColumns={@joincolumn(name=\"phonenumber_id\", referencedColumnName=\"id\", unique=true)})");
  153. assertEquals("JoinTable", parsedLine.getName());
  154. assertEquals("(name=\"users_phonenumbers\", joinColumns={@joincolumn(name=\"user_id\", referencedColumnName=\"id\")}, inverseJoinColumns={@joincolumn(name=\"phonenumber_id\", referencedColumnName=\"id\", unique=true)})", parsedLine.getDescription());
  155. Map<OffsetRange, String> types = parsedLine.getTypes();
  156. assertNotNull(types);
  157. assertEquals(3, types.size());
  158. String type1 = types.get(new OffsetRange(0, 18));
  159. assertEquals("\\Foo\\Bar\\jointable", type1);
  160. String type2 = types.get(new OffsetRange(60, 70));
  161. assertEquals("joincolumn", type2);
  162. String type3 = types.get(new OffsetRange(137, 147));
  163. assertEquals("joincolumn", type3);
  164. }
  165. public void testValidUseCase_11() throws Exception {
  166. AnnotationParsedLine parsedLine = parser.parse("\\Foo\\Bar\\JoinTable(name=\"users_phonenumbers\", joinColumns={@Baz\\JoinColumn(name=\"user_id\", referencedColumnName=\"id\")}, inverseJoinColumns={@JoinColumn(name=\"phonenumber_id\", referencedColumnName=\"id\", unique=true)})");
  167. assertEquals("JoinTable", parsedLine.getName());
  168. assertEquals("(name=\"users_phonenumbers\", joinColumns={@Baz\\JoinColumn(name=\"user_id\", referencedColumnName=\"id\")}, inverseJoinColumns={@JoinColumn(name=\"phonenumber_id\", referencedColumnName=\"id\", unique=true)})", parsedLine.getDescription());
  169. Map<OffsetRange, String> types = parsedLine.getTypes();
  170. assertNotNull(types);
  171. assertEquals(3, types.size());
  172. String type1 = types.get(new OffsetRange(0, 18));
  173. assertEquals("\\Foo\\Bar\\JoinTable", type1);
  174. String type2 = types.get(new OffsetRange(60, 74));
  175. assertEquals("Baz\\JoinColumn", type2);
  176. String type3 = types.get(new OffsetRange(141, 151));
  177. assertEquals("JoinColumn", type3);
  178. }
  179. }