Skip to content

Commit

Permalink
Add a new test for getContainerDefaultConfigurator
Browse files Browse the repository at this point in the history
  • Loading branch information
markt-asf committed Jan 13, 2022
1 parent c50f147 commit 37e05ba
Show file tree
Hide file tree
Showing 6 changed files with 172 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, 2020 Oracle and/or its affiliates and others.
* Copyright (c) 2013, 2021 Oracle and/or its affiliates and others.
* All rights reserved.
*
* This program and the accompanying materials are made available under the
Expand Down Expand Up @@ -46,6 +46,8 @@ public Set<Class<?>> getAnnotatedEndpointClasses(Set<Class<?>> scanned) {
set.add(WSCOriginServerReturningFalse.class);
set.add(WSCOriginServerReturningFalseConfigurator.class);
set.add(WSCModifyHandshakeServer.class);
set.add(WSCGetContainerDefaultConfiguratorServerA.class);
set.add(WSCGetContainerDefaultConfiguratorServerB.class);
return set;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright (c) 2021 Contributors to the Eclipse Foundation.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
* version 2 with the GNU Classpath Exception, which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
*/
package com.sun.ts.tests.websocket.ee.jakarta.websocket.server.serverendpointconfig.configurator;

import jakarta.websocket.server.ServerEndpointConfig.Configurator;

public class ContainerDefaultConfiguratorA extends Configurator {

private static String containerDefaultConfiguratorID;

public ContainerDefaultConfiguratorA() {
Configurator c = getContainerDefaultConfigurator();
containerDefaultConfiguratorID = Integer.toString(System.identityHashCode(c));
}

public static String getPlatformDefaultConfiguratorID() {
return containerDefaultConfiguratorID;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright (c) 2021 Contributors to the Eclipse Foundation.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
* version 2 with the GNU Classpath Exception, which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
*/
package com.sun.ts.tests.websocket.ee.jakarta.websocket.server.serverendpointconfig.configurator;

import jakarta.websocket.server.ServerEndpointConfig.Configurator;

public class ContainerDefaultConfiguratorB extends Configurator {

private static String containerDefaultConfiguratorID;

public ContainerDefaultConfiguratorB() {
Configurator c = getContainerDefaultConfigurator();
containerDefaultConfiguratorID = Integer.toString(System.identityHashCode(c));
}

public static String getPlatformDefaultConfiguratorID() {
return containerDefaultConfiguratorID;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -387,4 +387,23 @@ public void modifyHandshakeRequestTest() throws Fault {
public void modifyHandshakeResponseTest() throws Fault {
invoke("modifyhandshake", "response", "true");
}
/*
* @testName: getContainerDefaultConfiguratorTest
*
* @assertion_ids:
*
* @test_Strategy: Obtain the container default configurator from two separate
* endpoints and check that the same object is ontained.
*/

public void getContainerDefaultConfiguratorTest() throws Fault {
invoke("containerdefaultconfiguratorA", "anything", "");
String containerdefaultconfiguratorIdA = getResponseAsString();

invoke("containerdefaultconfiguratorB", "anything", "");
String containerdefaultconfiguratorIdB = getResponseAsString();

assertEquals(containerdefaultconfiguratorIdA, containerdefaultconfiguratorIdB,
"Different instances returned for container default configurator");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright (c) 2021 Contributors to the Eclipse Foundation.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
* version 2 with the GNU Classpath Exception, which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
*/
package com.sun.ts.tests.websocket.ee.jakarta.websocket.server.serverendpointconfig.configurator;

import java.io.IOException;

import jakarta.websocket.OnError;
import jakarta.websocket.OnMessage;
import jakarta.websocket.Session;
import jakarta.websocket.server.ServerEndpoint;

import com.sun.ts.tests.websocket.common.util.IOUtil;

@ServerEndpoint(value = "/containerdefaultconfiguratorA", configurator = ContainerDefaultConfiguratorA.class)
public class WSCGetContainerDefaultConfiguratorServerA {

@SuppressWarnings("unused")
@OnMessage
public String onMessage(String msg) {
String response = ContainerDefaultConfiguratorA.getPlatformDefaultConfiguratorID();
return response;
}

@OnError
public void onError(Session session, Throwable thr) throws IOException {
thr.printStackTrace(); // Write to error log, too
String message = IOUtil.printStackTrace(thr);
session.getBasicRemote().sendText(message);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright (c) 2021 Contributors to the Eclipse Foundation.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
* version 2 with the GNU Classpath Exception, which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
*/
package com.sun.ts.tests.websocket.ee.jakarta.websocket.server.serverendpointconfig.configurator;

import java.io.IOException;

import jakarta.websocket.OnError;
import jakarta.websocket.OnMessage;
import jakarta.websocket.Session;
import jakarta.websocket.server.ServerEndpoint;

import com.sun.ts.tests.websocket.common.util.IOUtil;

@ServerEndpoint(value = "/containerdefaultconfiguratorB", configurator = ContainerDefaultConfiguratorB.class)
public class WSCGetContainerDefaultConfiguratorServerB {

@SuppressWarnings("unused")
@OnMessage
public String onMessage(String msg) {
String response = ContainerDefaultConfiguratorB.getPlatformDefaultConfiguratorID();
return response;
}

@OnError
public void onError(Session session, Throwable thr) throws IOException {
thr.printStackTrace(); // Write to error log, too
String message = IOUtil.printStackTrace(thr);
session.getBasicRemote().sendText(message);
}
}

0 comments on commit 37e05ba

Please sign in to comment.