snuyanzin commented on code in PR #26385:
URL: https://github.com/apache/flink/pull/26385#discussion_r2031795676


##########
flink-table/flink-table-api-java/src/test/java/org/apache/flink/table/api/TableEnvironmentTest.java:
##########
@@ -158,6 +167,121 @@ void testTableFromDescriptor() {
         assertThat(tEnv.getCatalogManager().listTables()).isEmpty();
     }
 
+    @Test
+    void testCreateModelFromDescriptor() throws Exception {
+        final TableEnvironmentMock tEnv = 
TableEnvironmentMock.getStreamingInstance();
+
+        assertCreateModelFromDescriptor(tEnv, false);
+    }
+
+    @Test
+    void testCreateModelIgnoreIfExistsFromDescriptor() throws Exception {
+        final TableEnvironmentMock tEnv = 
TableEnvironmentMock.getStreamingInstance();
+
+        assertCreateModelFromDescriptor(tEnv, true);
+        assertThatNoException()
+                .isThrownBy(() -> tEnv.createModel("M", TEST_MODEL_DESCRIPTOR, 
true));
+
+        assertThatThrownBy(() -> tEnv.createModel("M", TEST_MODEL_DESCRIPTOR, 
false))
+                .isInstanceOf(ValidationException.class)
+                .hasMessage(
+                        "Could not execute CreateModel in path 
`default_catalog`.`default_database`.`M`");
+    }
+
+    @Test
+    void testCreateModelWithSameName() {
+        final TableEnvironmentMock tEnv = 
TableEnvironmentMock.getStreamingInstance();
+
+        tEnv.createModel("M", TEST_MODEL_DESCRIPTOR);
+
+        tEnv.createModel("M", TEST_MODEL_DESCRIPTOR, true);
+
+        assertThatThrownBy(() -> tEnv.createModel("M", TEST_MODEL_DESCRIPTOR, 
false))
+                .isInstanceOf(ValidationException.class)
+                .hasMessage(
+                        "Could not execute CreateModel in path 
`default_catalog`.`default_database`.`M`");
+
+        assertThatThrownBy(() -> tEnv.createModel("M", TEST_MODEL_DESCRIPTOR))
+                .isInstanceOf(ValidationException.class)
+                .hasMessage(
+                        "Could not execute CreateModel in path 
`default_catalog`.`default_database`.`M`");
+    }
+
+    @Test
+    void testDropModel() throws Exception {
+        final TableEnvironmentMock tEnv = 
TableEnvironmentMock.getStreamingInstance();
+
+        tEnv.createModel("M", TEST_MODEL_DESCRIPTOR);
+
+        final String catalog = tEnv.getCurrentCatalog();
+        final String database = tEnv.getCurrentDatabase();
+        final ObjectPath objectPath = new ObjectPath(database, "M");
+        CatalogModel catalogModel =
+                
tEnv.getCatalog(catalog).orElseThrow(AssertionError::new).getModel(objectPath);
+        assertThat(catalogModel).isInstanceOf(CatalogModel.class);
+        assertThat(tEnv.dropModel("M", true)).isTrue();
+        assertThatThrownBy(
+                        () ->
+                                tEnv.getCatalog(catalog)
+                                        .orElseThrow(AssertionError::new)
+                                        .getModel(objectPath))
+                .isInstanceOf(ModelNotExistException.class)
+                .hasMessage("Model '`default_catalog`.`default_database`.`M`' 
does not exist.");
+    }
+
+    @Test
+    void testNonExistingDropModel() throws Exception {
+        final TableEnvironmentMock tEnv = 
TableEnvironmentMock.getStreamingInstance();
+
+        assertThat(tEnv.dropModel("M", true)).isFalse();
+
+        assertThatThrownBy(() -> tEnv.dropModel("M", false))
+                .isInstanceOf(ValidationException.class)
+                .hasMessage(
+                        "Model with identifier 
'default_catalog.default_database.M' does not exist.");
+    }
+
+    @Test
+    void testCreateTemporaryModelFromDescriptor() {
+        final TableEnvironmentMock tEnv = 
TableEnvironmentMock.getStreamingInstance();
+        assertTemporaryCreateModelFromDescriptor(tEnv, false);
+    }
+
+    @Test
+    void testCreateTemporaryModelIfNotExistsFromDescriptor() {
+        final TableEnvironmentMock tEnv = 
TableEnvironmentMock.getStreamingInstance();
+
+        assertTemporaryCreateModelFromDescriptor(tEnv, true);
+        assertThatNoException()
+                .isThrownBy(() -> tEnv.createTemporaryModel("M", 
TEST_MODEL_DESCRIPTOR, true));
+
+        assertThatThrownBy(() -> tEnv.createTemporaryModel("M", 
TEST_MODEL_DESCRIPTOR, false))
+                .isInstanceOf(ValidationException.class)
+                .hasMessage(
+                        "Temporary model 
'`default_catalog`.`default_database`.`M`' already exists");
+    }
+
+    @Test
+    void testCreateModelWithSameNameIgnoreIfExists() {
+        final TableEnvironmentMock tEnv = 
TableEnvironmentMock.getStreamingInstance();
+
+        tEnv.createModel("M", TEST_MODEL_DESCRIPTOR);
+        tEnv.createModel("M", TEST_MODEL_DESCRIPTOR, true);
+    }
+
+    @Test
+    void testListModels() {
+        final TableEnvironmentMock tEnv = 
TableEnvironmentMock.getStreamingInstance();

Review Comment:
   Am I right that we have this line for every test in that class?
   If so why can't we extract it into a separate field and initialize just with 
`BerforeEach` ?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@flink.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to