Migrate to Junit 5 Jupiter
[lttng-ust-java-tests.git] / lttng-ust-java-tests-common / src / test / java / org / lttng / ust / agent / context / ContextRegistrationIT.java
CommitLineData
4d793724
AM
1/*
2 * Copyright (C) 2016, EfficiOS Inc., Alexandre Montplaisir <alexmonthy@efficios.com>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17 */
18
19package org.lttng.ust.agent.context;
20
7a4f0255
MJ
21import static org.junit.jupiter.api.Assertions.assertEquals;
22import static org.junit.jupiter.api.Assertions.assertFalse;
23import static org.junit.jupiter.api.Assertions.assertNull;
24import static org.junit.jupiter.api.Assertions.assertTrue;
25import static org.junit.jupiter.api.Assertions.fail;
4d793724
AM
26
27import java.io.IOException;
28
7a4f0255
MJ
29import org.junit.jupiter.api.Test;
30import org.junit.jupiter.api.extension.ExtendWith;
31import org.junit.jupiter.api.BeforeEach;
32import org.lttng.ust.agent.utils.TestPrintExtension;
4d793724
AM
33
34/**
35 * Generic tests related to the context retrieval mechanisms.
36 *
37 * @author Alexandre Montplaisir
38 */
7a4f0255 39@ExtendWith(TestPrintExtension.class)
4d793724
AM
40public class ContextRegistrationIT {
41
42 private ContextInfoManager mgr;
43
44 /**
45 * Test setup
46 */
7a4f0255 47 @BeforeEach
4d793724
AM
48 public void testSetup() {
49 try {
50 mgr = ContextInfoManager.getInstance();
51 } catch (SecurityException | IOException e) {
1f3dd43c 52 fail(e.getMessage());
4d793724
AM
53 }
54 }
55
56 /**
57 * Test registration and unregistration of a basic retriever.
58 */
59 @Test
60 public void testRegistration() {
390fca17 61 final String retrieverName = "test.retriever";
4d793724
AM
62 final IContextInfoRetriever emptyRetriever = (key -> null);
63
390fca17
AM
64 boolean ret = mgr.registerContextInfoRetriever(retrieverName, emptyRetriever);
65 assertTrue(ret);
4d793724
AM
66
67 IContextInfoRetriever retriever2 = mgr.getContextInfoRetriever(retrieverName);
68 assertEquals(emptyRetriever, retriever2);
69
70 mgr.unregisterContextInfoRetriever(retrieverName);
71 }
390fca17
AM
72
73 /**
74 * Test registration of retrievers with invalid names.
75 */
76 @Test
77 public void testRegistrationInvalid() {
78 String[] invalidNames = new String[] { "test.rétriever", "with space", "1numberfirst" };
79 for (String retrieverName : invalidNames) {
80 final IContextInfoRetriever emptyRetriever = (key -> null);
81
82 boolean ret = mgr.registerContextInfoRetriever(retrieverName, emptyRetriever);
83 assertFalse(ret);
84
85 IContextInfoRetriever retriever = mgr.getContextInfoRetriever(retrieverName);
86 assertNull(retriever);
87 }
88 }
4d793724 89}
This page took 0.02608 seconds and 4 git commands to generate.