Migrate TestNG to Junit5
[sdc/sdc-tosca.git] / sdc-tosca / src / test / java / org / onap / sdc / impl / BaseSetupExtension.java
1 package org.onap.sdc.impl;
2
3 import static org.junit.jupiter.api.extension.ExtensionContext.Namespace.GLOBAL;
4
5 import org.junit.jupiter.api.extension.BeforeAllCallback;
6 import org.junit.jupiter.api.extension.ExtensionContext;
7 import org.onap.sdc.tosca.parser.exceptions.SdcToscaParserException;
8
9 public abstract class BaseSetupExtension implements BeforeAllCallback, ExtensionContext.Store.CloseableResource {
10
11     @Override
12     public void beforeAll(ExtensionContext context) throws Exception {
13         // We need to use a unique key here, across all usages of this particular extension.
14         String uniqueKey = this.getClass().getName();
15         Object value = context.getRoot().getStore(GLOBAL).get(uniqueKey);
16         if (value == null) {
17             // First test container invocation.
18             context.getRoot().getStore(GLOBAL).put(uniqueKey, this);
19             setup();
20         }
21     }
22
23     // Callback that is invoked <em>exactly once</em>
24     // before the start of <em>all</em> test containers.
25     abstract void setup() throws SdcToscaParserException;
26
27     // Callback that is invoked <em>exactly once</em>
28     // after the end of <em>all</em> test containers.
29     // Inherited from {@code CloseableResource}
30     public abstract void close() throws Throwable;
31 }