|
| 1 | +/* |
| 2 | + * Copyright 2022 RelationalAI, Inc. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"): you may |
| 5 | + * not use this file except in compliance with the License. You may obtain |
| 6 | + * a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 12 | + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 13 | + * License for the specific language governing permissions and limitations |
| 14 | + * under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package com.relationalai; |
| 18 | + |
| 19 | +import org.junit.jupiter.api.extension.BeforeAllCallback; |
| 20 | +import org.junit.jupiter.api.extension.ExtensionContext; |
| 21 | + |
| 22 | +import java.io.IOException; |
| 23 | + |
| 24 | +import static org.junit.jupiter.api.Assertions.assertTrue; |
| 25 | +import static org.junit.jupiter.api.extension.ExtensionContext.Namespace.GLOBAL; |
| 26 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
| 27 | + |
| 28 | +public class TestExtension implements BeforeAllCallback, ExtensionContext.Store.CloseableResource { |
| 29 | + private static boolean started = false; |
| 30 | + |
| 31 | + @Override |
| 32 | + public void beforeAll(ExtensionContext context) throws Exception { |
| 33 | + if (!started) { |
| 34 | + started = true; |
| 35 | + Client client = UnitTest.createClient(); |
| 36 | + Engine engine = client.createEngineWait(UnitTest.engineName); |
| 37 | + assertEquals(engine.name, UnitTest.engineName); |
| 38 | + assertEquals(engine.state, "PROVISIONED"); |
| 39 | + context.getRoot().getStore(GLOBAL).put("com.relationalai.test", this); |
| 40 | + } |
| 41 | + } |
| 42 | + |
| 43 | + @Override |
| 44 | + public void close() throws IOException, InterruptedException { |
| 45 | + Client client = UnitTest.createClient(); |
| 46 | + HttpError error = null; |
| 47 | + try { |
| 48 | + client.deleteEngineWait(UnitTest.engineName); |
| 49 | + } catch (HttpError e) { |
| 50 | + error = e; |
| 51 | + } |
| 52 | + assertTrue(error != null && error.statusCode == 404); |
| 53 | + } |
| 54 | +} |
0 commit comments