| /*=============================================================================# |
| # Copyright (c) 2018, 2020 Stephan Wahlbrink and others. |
| # |
| # This program and the accompanying materials are made available under the |
| # terms of the Eclipse Public License 2.0 which is available at |
| # https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 |
| # which is available at https://www.apache.org/licenses/LICENSE-2.0. |
| # |
| # SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 |
| # |
| # Contributors: |
| # Stephan Wahlbrink <sw@wahlbrink.eu> - initial API and implementation |
| #=============================================================================*/ |
| |
| package org.eclipse.statet.rhelp.server; |
| |
| import static org.junit.jupiter.api.Assertions.assertEquals; |
| import static org.junit.jupiter.api.Assertions.assertNotNull; |
| import static org.junit.jupiter.api.Assertions.assertTimeoutPreemptively; |
| import static org.junit.jupiter.api.Assumptions.assumeTrue; |
| |
| import java.time.Duration; |
| |
| import org.junit.jupiter.api.Assertions; |
| import org.junit.jupiter.api.Test; |
| import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable; |
| import org.junit.jupiter.api.extension.ExtendWith; |
| import org.springframework.beans.factory.annotation.Autowired; |
| import org.springframework.boot.test.context.SpringBootTest; |
| import org.springframework.context.annotation.Import; |
| import org.springframework.test.context.junit.jupiter.SpringExtension; |
| |
| import org.eclipse.statet.jcommons.lang.NonNullByDefault; |
| import org.eclipse.statet.jcommons.lang.Nullable; |
| import org.eclipse.statet.jcommons.runtime.AppEnvironment; |
| import org.eclipse.statet.jcommons.runtime.CommonsRuntime; |
| import org.eclipse.statet.jcommons.status.Status; |
| |
| import org.eclipse.statet.rhelp.core.REnvHelp; |
| import org.eclipse.statet.rhelp.core.RHelpManager; |
| import org.eclipse.statet.rj.renv.core.REnv; |
| import org.eclipse.statet.rj.renv.core.REnvConfiguration; |
| import org.eclipse.statet.rj.renv.core.REnvManager; |
| |
| |
| @ExtendWith(SpringExtension.class) |
| @SpringBootTest |
| @Import(ContextConfiguration.class) |
| @NonNullByDefault |
| public class ApplicationTests { |
| |
| |
| @Autowired |
| private @Nullable REnvManager rEnvManager; |
| |
| @Autowired |
| private @Nullable RHelpManager rHelpManager; |
| |
| |
| @Test |
| public void AppEnv_available() { |
| final AppEnvironment environment= CommonsRuntime.getEnvironment(); |
| assertNotNull(environment); |
| Assertions.assertEquals(Application.BUNDLE_ID, environment.getBundleId()); |
| } |
| |
| @Test |
| public void REnvManager_available() { |
| final REnvManager rEnvManager= this.rEnvManager; |
| assertNotNull(rEnvManager); |
| final REnv rEnv= rEnvManager.get("default", null); //$NON-NLS-1$ |
| assertNotNull(rEnv); |
| } |
| |
| @Test |
| @EnabledIfEnvironmentVariable(named = "STATET_TEST_FILES", matches = ".+") |
| public void REnvManager_Config_loaded() { |
| final REnvManager rEnvManager= assumeNotNull(this.rEnvManager); |
| final REnv rEnv= rEnvManager.get("default", null); //$NON-NLS-1$ |
| assertNotNull(rEnv); |
| final REnvConfiguration rEnvConfig= rEnv.get(REnvConfiguration.class); |
| assertNotNull(rEnvConfig); |
| final Status status= rEnvConfig.getValidationStatus(); |
| assertEquals(Status.OK, status.getSeverity()); |
| } |
| |
| |
| @Test |
| public void RHelpManager_available() { |
| final RHelpManager rHelpManager= this.rHelpManager; |
| assertNotNull(rHelpManager); |
| } |
| |
| |
| @Test |
| @EnabledIfEnvironmentVariable(named = "STATET_TEST_FILES", matches = ".+") |
| public void RHelp_available() { |
| final REnvManager rEnvManager= assumeNotNull(this.rEnvManager); |
| final REnv rEnv= assumeREnvValid(rEnvManager.get("default", null)); |
| |
| final RHelpManager rHelpManager= assumeNotNull(this.rHelpManager); |
| |
| assertTimeoutPreemptively(Duration.ofMinutes(10), |
| () -> { |
| while (true) { |
| final REnvHelp rEnvHelp= rHelpManager.getHelp(rEnv); |
| if (rEnvHelp != null) { |
| rEnvHelp.unlock(); |
| return; |
| } |
| } |
| }); |
| } |
| |
| |
| @SuppressWarnings("null") |
| private static <T> T assumeNotNull(final @Nullable T value) { |
| assumeTrue(value != null); |
| return value; |
| } |
| |
| @SuppressWarnings("null") |
| private static REnv assumeREnvValid(final @Nullable REnv rEnv) { |
| assumeTrue(rEnv != null); |
| final REnvConfiguration rEnvConfiguration= rEnv.get(REnvConfiguration.class); |
| assumeTrue(rEnvConfiguration != null |
| && rEnvConfiguration.getValidationStatus().getSeverity() == Status.OK ); |
| return rEnv; |
| } |
| |
| } |