/cayenne-server/src/test/java/org/apache/cayenne/dba/AutoAdapterIT.java

https://github.com/apache/cayenne · Java · 114 lines · 74 code · 15 blank · 25 comment · 0 complexity · ef42dcfd8ca4c99c3ec60316d0e51c62 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. * https://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.apache.cayenne.dba;
  20. import org.apache.cayenne.access.DataNode;
  21. import org.apache.cayenne.access.jdbc.SQLTemplateAction;
  22. import org.apache.cayenne.di.Inject;
  23. import org.apache.cayenne.log.NoopJdbcEventLogger;
  24. import org.apache.cayenne.query.ObjectSelect;
  25. import org.apache.cayenne.query.SQLTemplate;
  26. import org.apache.cayenne.testdo.testmap.Artist;
  27. import org.apache.cayenne.unit.di.server.CayenneProjects;
  28. import org.apache.cayenne.unit.di.server.ServerCase;
  29. import org.apache.cayenne.unit.di.server.UseServerRuntime;
  30. import org.junit.Test;
  31. import static org.junit.Assert.assertEquals;
  32. import static org.junit.Assert.assertFalse;
  33. import static org.junit.Assert.assertNotNull;
  34. import static org.junit.Assert.assertSame;
  35. @UseServerRuntime(CayenneProjects.TESTMAP_PROJECT)
  36. public class AutoAdapterIT extends ServerCase {
  37. @Inject
  38. private DataNode dataNode;
  39. @Test
  40. public void testGetAdapter_Proxy() {
  41. AutoAdapter adapter = new AutoAdapter(() -> dataNode.getAdapter(), NoopJdbcEventLogger.getInstance());
  42. DbAdapter detected = adapter.getAdapter();
  43. assertSame(dataNode.getAdapter(), detected);
  44. }
  45. @Test
  46. public void testCreateSQLTemplateAction() {
  47. AutoAdapter autoAdapter = new AutoAdapter(() -> dataNode.getAdapter(), NoopJdbcEventLogger.getInstance());
  48. SQLTemplateAction action = (SQLTemplateAction) autoAdapter.getAction(new SQLTemplate(Artist.class,
  49. "select * from artist"), dataNode);
  50. // it is important for SQLTemplateAction to be used with unwrapped adapter,
  51. // as the adapter class name is used as a key to the correct SQL template.
  52. assertNotNull(action.getAdapter());
  53. assertFalse(action.getAdapter() instanceof AutoAdapter);
  54. assertSame(dataNode.getAdapter(), action.getAdapter());
  55. }
  56. @Test
  57. public void testCorrectProxyMethods() {
  58. DbAdapter adapter = dataNode.getAdapter();
  59. AutoAdapter autoAdapter = new AutoAdapter(() -> adapter, NoopJdbcEventLogger.getInstance());
  60. ObjectSelect<Artist> select = ObjectSelect.query(Artist.class);
  61. // query related methods
  62. assertEquals(adapter.supportsBatchUpdates(),
  63. autoAdapter.supportsBatchUpdates());
  64. assertEquals(adapter.supportsGeneratedKeys(),
  65. autoAdapter.supportsGeneratedKeys());
  66. assertEquals(adapter.supportsGeneratedKeysForBatchInserts(),
  67. autoAdapter.supportsGeneratedKeysForBatchInserts());
  68. assertSame(adapter.getBatchTerminator(),
  69. autoAdapter.getBatchTerminator());
  70. assertSame(adapter.getPkGenerator(),
  71. autoAdapter.getPkGenerator());
  72. assertSame(adapter.getQuotingStrategy(),
  73. autoAdapter.getQuotingStrategy());
  74. // returns a new instance for each call
  75. assertSame(adapter.getSqlTreeProcessor().getClass(),
  76. autoAdapter.getSqlTreeProcessor().getClass());
  77. assertSame(adapter.getExtendedTypes(),
  78. autoAdapter.getExtendedTypes());
  79. assertSame(adapter.getEjbqlTranslatorFactory(),
  80. autoAdapter.getEjbqlTranslatorFactory());
  81. // returns a new instance for each call
  82. assertSame(adapter.getSelectTranslator(select, dataNode.getEntityResolver()).getClass(),
  83. autoAdapter.getSelectTranslator(select, dataNode.getEntityResolver()).getClass());
  84. // reverse engineering related methods
  85. assertEquals(adapter.supportsCatalogsOnReverseEngineering(),
  86. autoAdapter.supportsCatalogsOnReverseEngineering());
  87. assertSame(adapter.getSystemCatalogs(),
  88. autoAdapter.getSystemCatalogs());
  89. assertSame(adapter.getSystemSchemas(),
  90. autoAdapter.getSystemSchemas());
  91. assertSame(adapter.tableTypeForTable(),
  92. autoAdapter.tableTypeForTable());
  93. assertSame(adapter.tableTypeForView(),
  94. autoAdapter.tableTypeForView());
  95. // db generation related methods
  96. assertEquals(adapter.supportsUniqueConstraints(),
  97. autoAdapter.supportsUniqueConstraints());
  98. }
  99. }