/**
* Copyright (c) 2000-present Liferay, Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*/
package com.liferay.portal.kernel.nio.intraband.mailbox;
import com.liferay.portal.kernel.io.Deserializer;
import com.liferay.portal.kernel.nio.intraband.Datagram;
import com.liferay.portal.kernel.nio.intraband.PortalExecutorManagerUtilAdvice;
import com.liferay.portal.kernel.nio.intraband.SystemDataType;
import com.liferay.portal.kernel.nio.intraband.test.MockIntraband;
import com.liferay.portal.kernel.nio.intraband.test.MockRegistrationReference;
import com.liferay.portal.kernel.test.rule.AggregateTestRule;
import com.liferay.portal.kernel.test.rule.CodeCoverageAssertor;
import com.liferay.portal.kernel.test.rule.NewEnv;
import com.liferay.portal.kernel.util.PropsUtilAdvice;
import com.liferay.portal.test.rule.AdviseWith;
import com.liferay.portal.test.rule.AspectJNewEnvTestRule;
import com.liferay.registry.BasicRegistryImpl;
import com.liferay.registry.RegistryUtil;
import java.nio.ByteBuffer;
import org.junit.Assert;
import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
/**
* @author Shuyang Zhou
*/
public class MailboxDatagramReceiveHandlerTest {
@ClassRule
@Rule
public static final AggregateTestRule aggregateTestRule =
new AggregateTestRule(
CodeCoverageAssertor.INSTANCE, AspectJNewEnvTestRule.INSTANCE);
@Before
public void setUp() {
RegistryUtil.setRegistry(new BasicRegistryImpl());
}
@AdviseWith(
adviceClasses = {
PropsUtilAdvice.class, PortalExecutorManagerUtilAdvice.class
}
)
@NewEnv(type = NewEnv.Type.CLASSLOADER)
@Test
public void testDoReceive() {
MailboxDatagramReceiveHandler mailboxDatagramReceiveHandler =
new MailboxDatagramReceiveHandler();
MockIntraband mockIntraband = new MockIntraband();
SystemDataType systemDataType = SystemDataType.MAILBOX;
mailboxDatagramReceiveHandler.doReceive(
new MockRegistrationReference(mockIntraband),
Datagram.createRequestDatagram(
systemDataType.getValue(), ByteBuffer.allocate(0)));
Datagram responseDatagram = mockIntraband.getDatagram();
Deserializer deserializer = new Deserializer(
responseDatagram.getDataByteBuffer());
Assert.assertEquals(0, deserializer.readLong());
}
}