|
Apache CXF example source code file (JAXRSLoggingAtomPushSpringTest.java)
The Apache CXF JAXRSLoggingAtomPushSpringTest.java source code/** * 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.cxf.systest.jaxrs; import java.io.StringReader; import java.util.ArrayList; import java.util.List; import java.util.logging.Level; import java.util.logging.LogRecord; import java.util.logging.Logger; import javax.ws.rs.GET; import javax.ws.rs.POST; import javax.ws.rs.Path; import javax.xml.bind.JAXBContext; import javax.xml.namespace.QName; import org.apache.abdera.model.Element; import org.apache.abdera.model.Entry; import org.apache.abdera.model.ExtensibleElement; import org.apache.abdera.model.Feed; import org.apache.cxf.common.logging.LogUtils; import org.apache.cxf.jaxrs.client.WebClient; import org.apache.cxf.management.web.logging.LogRecords; import org.apache.cxf.testutil.common.AbstractClientServerTestBase; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Ignore; import org.junit.Test; public class JAXRSLoggingAtomPushSpringTest extends AbstractClientServerTestBase { public static final String PORT = SpringServer.PORT; private JAXBContext context; private int fakyLogger; private int namedLogger; private int resourceLogger; private int throwables; @BeforeClass public static void beforeClass() throws Exception { // must be 'in-process' to communicate with inner class in single JVM // and to spawn class SpringServer w/o using main() method launchServer(SpringServer.class, true); } @Ignore public static class SpringServer extends AbstractSpringServer { public SpringServer() { super("/jaxrs_logging_atompush"); } } @Before public void before() throws Exception { Resource.clear(); Resource2.clear(); Resource3.clear(); Resource4.clear(); Resource5.clear(); context = JAXBContext.newInstance(LogRecords.class, org.apache.cxf.management.web.logging.LogRecord.class); } @Test public void testFeedsWithLogRecordsOneEntry() throws Exception { WebClient wc = WebClient.create("http://localhost:" + PORT + "/root"); try { wc.path("/log").get(); } catch (Exception ex) { //ignore } Thread.sleep(3000); List<Feed> elements = Resource.getElements(); assertEquals(8, elements.size()); resetCounters(); for (Feed feed : elements) { List<Entry> entries = feed.getEntries(); assertEquals(1, entries.size()); Entry e = entries.get(0); LogRecords records = readLogRecords(e.getContent()); List<org.apache.cxf.management.web.logging.LogRecord> list = records.getLogRecords(); assertNotNull(list); assertEquals(1, list.size()); updateCounters(list.get(0), "Resource"); } verifyCounters(); } @Test public void testFeedsWithBatchLogRecordsOneEntry() throws Exception { WebClient wc = WebClient.create("http://localhost:" + PORT + "/batch"); wc.path("/log").get(); Thread.sleep(3000); List<Feed> elements = Resource2.getElements(); assertEquals(2, elements.size()); resetCounters(); for (Feed feed : elements) { List<Entry> entries = feed.getEntries(); assertEquals(4, entries.size()); for (Entry e : entries) { updateCounters(readLogRecord(e.getContent()), "Resource2"); } } verifyCounters(); } @Test public void testEntriesWithLogRecordsOneEntry() throws Exception { WebClient wc = WebClient.create("http://localhost:" + PORT + "/entries"); wc.path("/log").get(); Thread.sleep(3000); List<Entry> elements = Resource3.getElements(); assertEquals(8, elements.size()); resetCounters(); for (Entry e : elements) { updateCounters(readLogRecord(e.getContent()), "Resource3"); } verifyCounters(); } @Test public void testManyEntries() throws Exception { WebClient wc = WebClient.create("http://localhost:" + PORT + "/entriesMany"); wc.path("/log").get(); Thread.sleep(3000); List<Entry> elements = Resource4.getElements(); assertEquals(4, elements.size()); resetCounters(); for (Entry e : elements) { LogRecords records = readLogRecords(e.getContent()); List<org.apache.cxf.management.web.logging.LogRecord> list = records.getLogRecords(); assertNotNull(list); assertEquals(2, list.size()); for (org.apache.cxf.management.web.logging.LogRecord record : list) { updateCounters(record, "Resource4"); } } verifyCounters(); } @Test public void testFeedsWithLogRecordsExtension() throws Exception { WebClient wc = WebClient.create("http://localhost:" + PORT + "/extensions"); wc.path("/log").get(); Thread.sleep(3000); List<Feed> elements = Resource5.getElements(); assertEquals(8, elements.size()); resetCounters(); for (Feed feed : elements) { List<Entry> entries = feed.getEntries(); assertEquals(1, entries.size()); Entry e = entries.get(0); LogRecords records = readLogRecordsExtension(e); List<org.apache.cxf.management.web.logging.LogRecord> list = records.getLogRecords(); assertNotNull(list); assertEquals(1, list.size()); updateCounters(list.get(0), "Resource5"); } verifyCounters(); } @Ignore @Path("/root") public static class Resource { private static final Logger LOG1; private static final Logger LOG2; static { System.gc(); LOG1 = LogUtils.getL7dLogger(Resource.class); LOG2 = LogUtils.getL7dLogger(Resource.class, null, "namedLogger"); } private static List<Feed> feeds = new ArrayList Other Apache CXF examples (source code examples)Here is a short list of links related to this Apache CXF JAXRSLoggingAtomPushSpringTest.java source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.