Skip to content

Commit

Permalink
W-16656937: add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
pdmoineau committed Sep 12, 2024
1 parent e3ec850 commit 277d8bd
Showing 1 changed file with 39 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/**
* Copyright (c) 2018, salesforce.com, inc.
* All rights reserved.
* SPDX-License-Identifier: BSD-3-Clause
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
package com.demandware.core.metric;

import java.net.InetAddress;
import java.net.UnknownHostException;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

public class TestUtil
{
private static String falconPrefix = "cc-umon-client.falcon-fi";
private static String umDevPrefix = "um.dev.carbonj.";

@Test
public void testGetGraphiteMetricPrefix() throws UnknownHostException
{
String fqdn = InetAddress.getLocalHost().getHostName();
String hostname = fqdn.substring(0, fqdn.indexOf( "." ) == -1 ? fqdn.length() : fqdn.indexOf( "." ) );

// Verify provided prefix with hostname
assertEquals(falconPrefix + "." + hostname, Util.getGraphiteMetricPrefix(falconPrefix, true, -1, "00", "v1"));

// Verify provided prefix without hostname
assertEquals(falconPrefix, Util.getGraphiteMetricPrefix(falconPrefix, false, -1, "00", "v1"));

// Verify prefix if podId is provided
assertEquals("pod100.00.carbonj." + hostname + ".v1", Util.getGraphiteMetricPrefix(null, false, 100, "00", "v1"));

// Verify prefix if podId and prefix aren't provided
assertEquals(umDevPrefix + hostname, Util.getGraphiteMetricPrefix(null, false, -1, "00", "v1"));
}
}

0 comments on commit 277d8bd

Please sign in to comment.