2 * Copyright (C) 2016, EfficiOS Inc., Alexandre Montplaisir <alexmonthy@efficios.com>
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.
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.
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.
19 package org
.lttng
.ust
.agent
.context
;
21 import static org
.junit
.jupiter
.api
.Assertions
.assertEquals
;
22 import static org
.junit
.jupiter
.api
.Assertions
.assertFalse
;
23 import static org
.junit
.jupiter
.api
.Assertions
.assertNull
;
24 import static org
.junit
.jupiter
.api
.Assertions
.assertTrue
;
25 import static org
.junit
.jupiter
.api
.Assertions
.fail
;
27 import java
.io
.IOException
;
29 import org
.junit
.jupiter
.api
.Test
;
30 import org
.junit
.jupiter
.api
.extension
.ExtendWith
;
31 import org
.junit
.jupiter
.api
.BeforeEach
;
32 import org
.lttng
.ust
.agent
.utils
.TestPrintExtension
;
35 * Generic tests related to the context retrieval mechanisms.
37 * @author Alexandre Montplaisir
39 @ExtendWith(TestPrintExtension
.class)
40 public class ContextRegistrationIT
{
42 private ContextInfoManager mgr
;
48 public void testSetup() {
50 mgr
= ContextInfoManager
.getInstance();
51 } catch (SecurityException
| IOException e
) {
57 * Test registration and unregistration of a basic retriever.
60 public void testRegistration() {
61 final String retrieverName
= "test.retriever";
62 final IContextInfoRetriever emptyRetriever
= (key
-> null);
64 boolean ret
= mgr
.registerContextInfoRetriever(retrieverName
, emptyRetriever
);
67 IContextInfoRetriever retriever2
= mgr
.getContextInfoRetriever(retrieverName
);
68 assertEquals(emptyRetriever
, retriever2
);
70 mgr
.unregisterContextInfoRetriever(retrieverName
);
74 * Test registration of retrievers with invalid names.
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);
82 boolean ret
= mgr
.registerContextInfoRetriever(retrieverName
, emptyRetriever
);
85 IContextInfoRetriever retriever
= mgr
.getContextInfoRetriever(retrieverName
);
86 assertNull(retriever
);