Skip to content

Commit

Permalink
Add LicenseService tests
Browse files Browse the repository at this point in the history
  • Loading branch information
magaupp committed Dec 29, 2024
1 parent 5fb3abf commit cc774a5
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package de.tum.cit.aet.artemis.core.config;

import static org.assertj.core.api.Assertions.assertThat;

import org.junit.jupiter.api.Test;

class LicenseConfigurationTest {

@Test
void testMatlabLicenseServer() {
String licenseServer = "1234@license-server";
LicenseConfiguration licenseConfiguration = new LicenseConfiguration(new LicenseConfiguration.MatLabLicense(licenseServer));
assertThat(licenseConfiguration.getMatlabLicenseServer()).isEqualTo(licenseServer);
}

@Test
void testMatlabNullRecord() {
LicenseConfiguration licenseConfiguration = new LicenseConfiguration(null);
assertThat(licenseConfiguration.getMatlabLicenseServer()).isNull();
}

@Test
void testMatlabNullValue() {
LicenseConfiguration licenseConfiguration = new LicenseConfiguration(new LicenseConfiguration.MatLabLicense(null));
assertThat(licenseConfiguration.getMatlabLicenseServer()).isNull();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package de.tum.cit.aet.artemis.programming.service;

import static org.assertj.core.api.Assertions.assertThat;

import java.util.Map;

import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;

import de.tum.cit.aet.artemis.core.config.LicenseConfiguration;
import de.tum.cit.aet.artemis.programming.domain.ProgrammingLanguage;
import de.tum.cit.aet.artemis.programming.domain.ProjectType;
import de.tum.cit.aet.artemis.shared.base.AbstractSpringIntegrationIndependentTest;

class LicenseServiceTest extends AbstractSpringIntegrationIndependentTest {

@Autowired
private LicenseService licenseService;

@Test
void testIsLicensedNoneRequired() {
boolean isLicensed = licenseService.isLicensed(ProgrammingLanguage.JAVA, ProjectType.GRADLE_GRADLE);
assertThat(isLicensed).isTrue();
}

@Test
void testGetLicenseNoneRequired() {
Map<String, String> environment = licenseService.getEnvironment(ProgrammingLanguage.JAVA, ProjectType.GRADLE_GRADLE);
assertThat(environment).isEmpty();
}

@Test
void testIsLicensedMatlab() {
boolean isLicensed = licenseService.isLicensed(ProgrammingLanguage.MATLAB, null);
assertThat(isLicensed).isTrue();
}

@Test
void testGetLicenseMatlab() {
Map<String, String> environment = licenseService.getEnvironment(ProgrammingLanguage.MATLAB, null);
assertThat(environment).containsEntry("MLM_LICENSE_FILE", "1234@license-server");
}

@Test
void testIsLicensedMatlabUnlicensed() {
LicenseConfiguration licenseConfiguration = new LicenseConfiguration(null);
LicenseService licenseService = new LicenseService(licenseConfiguration);
boolean isLicensed = licenseService.isLicensed(ProgrammingLanguage.MATLAB, null);
assertThat(isLicensed).isFalse();
}
}
5 changes: 4 additions & 1 deletion src/test/resources/config/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,10 @@ artemis:
short-name: "artemis-build-agent-test"
telemetry:
enabled: false # setting this to false will disable sending any information to the telemetry service

licenses:
matlab:
license-server: "1234@license-server"

spring:
application:
name: Artemis
Expand Down

0 comments on commit cc774a5

Please sign in to comment.