|
29 | 29 | import com.kingsrook.qqq.backend.core.actions.tables.InsertAction; |
30 | 30 | import com.kingsrook.qqq.backend.core.context.QContext; |
31 | 31 | import com.kingsrook.qqq.backend.core.exceptions.QException; |
| 32 | +import com.kingsrook.qqq.backend.core.exceptions.QNotFoundException; |
32 | 33 | import com.kingsrook.qqq.backend.core.model.actions.processes.RunBackendStepInput; |
33 | 34 | import com.kingsrook.qqq.backend.core.model.actions.processes.RunProcessInput; |
34 | 35 | import com.kingsrook.qqq.backend.core.model.actions.processes.RunProcessOutput; |
|
49 | 50 | import org.junit.jupiter.api.AfterEach; |
50 | 51 | import org.junit.jupiter.api.BeforeEach; |
51 | 52 | import org.junit.jupiter.api.Test; |
| 53 | +import static org.assertj.core.api.Assertions.assertThatThrownBy; |
52 | 54 | import static org.junit.jupiter.api.Assertions.assertEquals; |
| 55 | +import static org.junit.jupiter.api.Assertions.assertNotNull; |
53 | 56 | import static org.junit.jupiter.api.Assertions.assertNull; |
54 | 57 | import static org.junit.jupiter.api.Assertions.assertTrue; |
55 | 58 |
|
@@ -82,6 +85,64 @@ void afterEach() |
82 | 85 |
|
83 | 86 |
|
84 | 87 |
|
| 88 | + /******************************************************************************* |
| 89 | + ** |
| 90 | + *******************************************************************************/ |
| 91 | + @Test |
| 92 | + void testSingleViewFetch() throws Exception |
| 93 | + { |
| 94 | + QInstance qInstance = QContext.getQInstance(); |
| 95 | + new SavedViewsMetaDataProvider() |
| 96 | + .withIsQuickSavedViewEnabled(true) |
| 97 | + .defineAll(qInstance, TestUtils.MEMORY_BACKEND_NAME, null); |
| 98 | + String tableName = TestUtils.TABLE_NAME_PERSON_MEMORY; |
| 99 | + |
| 100 | + /////////////////////////////////////////////////// |
| 101 | + // make sure a not-found view throws as expected // |
| 102 | + /////////////////////////////////////////////////// |
| 103 | + { |
| 104 | + assertThatThrownBy(() -> runQuerySavedViewsProcessForSingleView(tableName, -1)) |
| 105 | + .isInstanceOf(QNotFoundException.class); |
| 106 | + } |
| 107 | + |
| 108 | + ///////////////////////////////////////////////////// |
| 109 | + // insert one saved view, but no quick saved views // |
| 110 | + ///////////////////////////////////////////////////// |
| 111 | + Integer savedViewId; |
| 112 | + { |
| 113 | + savedViewId = new InsertAction().execute(new InsertInput(SavedView.TABLE_NAME).withRecordEntity( |
| 114 | + new SavedView().withTableName(tableName).withLabel("one").withUserId(QContext.getQSession().getUser().getIdReference()))).getRecords().get(0).getValueInteger("id"); |
| 115 | + |
| 116 | + QRecord savedView = runQuerySavedViewsProcessForSingleView(tableName, savedViewId); |
| 117 | + |
| 118 | + assertNotNull(savedView); |
| 119 | + assertEquals("one", savedView.getValue("label")); |
| 120 | + assertNull(savedView.getValue("type")); |
| 121 | + } |
| 122 | + |
| 123 | + /////////////////////////////////////////////////////////// |
| 124 | + // insert a quick saved view referencing that saved view // |
| 125 | + /////////////////////////////////////////////////////////// |
| 126 | + { |
| 127 | + new InsertAction().execute(new InsertInput(QuickSavedView.TABLE_NAME).withRecordEntity( |
| 128 | + new QuickSavedView().withLabel("Quickly").withSavedViewId(savedViewId).withDoCount(true).withSortOrder(17))); |
| 129 | + |
| 130 | + QRecord savedView = runQuerySavedViewsProcessForSingleView(tableName, savedViewId); |
| 131 | + assertNotNull(savedView); |
| 132 | + |
| 133 | + ////////////////////////////////////////////////////// |
| 134 | + // attributes should come from the quick-saved view // |
| 135 | + ////////////////////////////////////////////////////// |
| 136 | + assertEquals("quickView", savedView.getValue("type")); |
| 137 | + assertEquals("Quickly", savedView.getValue("label")); |
| 138 | + assertTrue(savedView.getValueBoolean("doCount")); |
| 139 | + assertEquals(17, savedView.getValue("sortOrder")); |
| 140 | + } |
| 141 | + |
| 142 | + } |
| 143 | + |
| 144 | + |
| 145 | + |
85 | 146 | /******************************************************************************* |
86 | 147 | ** |
87 | 148 | *******************************************************************************/ |
@@ -305,6 +366,22 @@ void testUserIdLock() throws Exception |
305 | 366 |
|
306 | 367 |
|
307 | 368 |
|
| 369 | + /*************************************************************************** |
| 370 | + * |
| 371 | + ***************************************************************************/ |
| 372 | + private static QRecord runQuerySavedViewsProcessForSingleView(String tableName, Integer id) throws QException |
| 373 | + { |
| 374 | + RunProcessInput runProcessInput = new RunProcessInput(); |
| 375 | + runProcessInput.setProcessName(QuerySavedViewProcess.getProcessMetaData().getName()); |
| 376 | + runProcessInput.addValue("tableName", tableName); |
| 377 | + runProcessInput.addValue("id", id); |
| 378 | + RunProcessOutput runProcessOutput = new RunProcessAction().execute(runProcessInput); |
| 379 | + QRecord savedView = (QRecord) runProcessOutput.getValue("savedView"); |
| 380 | + return savedView; |
| 381 | + } |
| 382 | + |
| 383 | + |
| 384 | + |
308 | 385 | /*************************************************************************** |
309 | 386 | * |
310 | 387 | ***************************************************************************/ |
|
0 commit comments