StorageHelper.java

  1. package com.soebes.itf.jupiter.extension;

  2. /*
  3.  * Licensed to the Apache Software Foundation (ASF) under one
  4.  * or more contributor license agreements.  See the NOTICE file
  5.  * distributed with this work for additional information
  6.  * regarding copyright ownership.  The ASF licenses this file
  7.  * to you under the Apache License, Version 2.0 (the
  8.  * "License"); you may not use this file except in compliance
  9.  * with the License.  You may obtain a copy of the License at
  10.  *
  11.  *  http://www.apache.org/licenses/LICENSE-2.0
  12.  *
  13.  * Unless required by applicable law or agreed to in writing,
  14.  * software distributed under the License is distributed on an
  15.  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  16.  * KIND, either express or implied.  See the License for the
  17.  * specific language governing permissions and limitations
  18.  * under the License.
  19.  */

  20. import com.soebes.itf.jupiter.maven.MavenCacheResult;
  21. import com.soebes.itf.jupiter.maven.MavenExecutionResult;
  22. import com.soebes.itf.jupiter.maven.MavenLog;
  23. import com.soebes.itf.jupiter.maven.MavenProjectResult;
  24. import org.junit.jupiter.api.extension.ExtensionContext;
  25. import org.junit.jupiter.api.extension.ExtensionContext.Namespace;
  26. import org.junit.jupiter.api.extension.ExtensionContext.Store;

  27. import java.nio.file.Path;

  28. /**
  29.  * @author Karl Heinz Marbaise
  30.  */
  31. final class StorageHelper {

  32.   private static final Namespace NAMESPACE_MAVEN_IT = Namespace.create(MavenITExtension.class);

  33.   private final Store nameSpace;

  34.   private final ExtensionContext context;

  35.   StorageHelper(ExtensionContext context) {
  36.     this.nameSpace = context.getStore(NAMESPACE_MAVEN_IT);
  37.     this.context = context;
  38.   }

  39.   <V> V get(Storage storage, Class<V> requiredType) {
  40.     return nameSpace.get(storage, requiredType);
  41.   }

  42.   <V> V get(Object key, Class<V> requiredType) {
  43.     return nameSpace.get(key, requiredType);
  44.   }

  45.   void put(Object key, Object value) {
  46.     nameSpace.put(key, value);
  47.   }

  48.   void save(Path targetTestClassesDirectory, Path mavenItTestCaseBaseDirectory, Path targetDirectory) {
  49.     StorageHelper sh = new StorageHelper(context);
  50.     sh.put(Storage.TARGET_MAVEN_IT_DIRECTORY, targetTestClassesDirectory);
  51.     sh.put(Storage.MAVEN_IT_TESTCASE_BASEDIRECTORY, mavenItTestCaseBaseDirectory);
  52.     sh.put(Storage.TARGET_DIRECTORY, targetDirectory);
  53.   }

  54.   void save(MavenExecutionResult result, MavenLog log, MavenCacheResult mavenCacheResult,
  55.             MavenProjectResult mavenProjectResult) {
  56.     put(ParameterType.ExecutionResult + context.getUniqueId(), result);
  57.     put(ParameterType.LogResult + context.getUniqueId(), log);
  58.     put(ParameterType.CacheResult + context.getUniqueId(), mavenCacheResult);
  59.     put(ParameterType.ProjectResult + context.getUniqueId(), mavenProjectResult);
  60.   }
  61. }