Skip to content

Commit

Permalink
feat: Add unit tests for CustomServiceTagResolver
Browse files Browse the repository at this point in the history
  • Loading branch information
tenthe committed Apr 30, 2024
1 parent 8c8ed98 commit 5ae1135
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 0 deletions.
12 changes: 12 additions & 0 deletions streampipes-service-extensions/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,18 @@
</exclusion>
</exclusions>
</dependency>

<!-- Test dependencies -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

package org.apache.streampipes.service.extensions;


import org.apache.streampipes.commons.environment.Environment;
import org.apache.streampipes.commons.environment.variable.StringEnvironmentVariable;
import org.apache.streampipes.model.extensions.svcdiscovery.SpServiceTag;
import org.apache.streampipes.model.extensions.svcdiscovery.SpServiceTagPrefix;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

class CustomServiceTagResolverTest {

private StringEnvironmentVariable customServiceTags;
private CustomServiceTagResolver resolver;

@BeforeEach
void setUp() {
var env = mock(Environment.class);
customServiceTags = mock(StringEnvironmentVariable.class);
when(env.getCustomServiceTags()).thenReturn(customServiceTags);
resolver = new CustomServiceTagResolver(env);
}

@Test
void returnsCustomServiceTagsWhenTheyExist() {
when(customServiceTags.exists()).thenReturn(true);
when(customServiceTags.getValue()).thenReturn("tag1,tag2");

var result = resolver.getCustomServiceTags();

assertEquals(2, result.size());
assertTrue(result.contains(SpServiceTag.create(SpServiceTagPrefix.CUSTOM, "tag1")));
assertTrue(result.contains(SpServiceTag.create(SpServiceTagPrefix.CUSTOM, "tag2")));
}

@Test
void returnsEmptySetWhenNoCustomServiceTagsExist() {
when(customServiceTags.exists()).thenReturn(false);

var result = resolver.getCustomServiceTags();

assertTrue(result.isEmpty());
}
}

0 comments on commit 5ae1135

Please sign in to comment.