PROX-86: modified method cancelled (#11)

* PROX-86: modified method cancelled

* PROX-86: remove unused classes
This commit is contained in:
Anatoly Cherkasov 2017-08-08 12:30:16 +03:00 committed by GitHub
parent d9092038e8
commit 0ddd0e5a47
10 changed files with 12 additions and 285 deletions

View File

@ -1,45 +0,0 @@
package com.rbkmoney.proxy.mocketbank.configuration;
import com.rbkmoney.damsel.cds.KeyringSrv;
import com.rbkmoney.woody.api.ClientBuilder;
import com.rbkmoney.woody.api.event.ClientEventListener;
import com.rbkmoney.woody.api.event.CompositeClientEventListener;
import com.rbkmoney.woody.thrift.impl.http.THSpawnClientBuilder;
import com.rbkmoney.woody.thrift.impl.http.event.ClientEventLogListener;
import com.rbkmoney.woody.thrift.impl.http.event.HttpClientEventLogListener;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.Resource;
import java.io.IOException;
@Configuration
public class CdsKeyringConfiguration {
@Value("${cds.url.keyring}")
private Resource resource;
@Bean
public KeyringSrv.Iface keyringSrv(ClientEventListener listenerSrv) throws IOException {
return clientBuilder()
.withEventListener(listenerSrv)
.withAddress(resource.getURI())
.build(KeyringSrv.Iface.class);
}
@Bean
@ConditionalOnMissingBean
public ClientEventListener listenerSrv() {
return new CompositeClientEventListener(
new ClientEventLogListener(),
new HttpClientEventLogListener()
);
}
@Bean(name = "clientBuilderKeyring")
public ClientBuilder clientBuilder() {
return new THSpawnClientBuilder();
}
}

View File

@ -1,14 +1,8 @@
package com.rbkmoney.proxy.mocketbank.configuration;
import com.rbkmoney.damsel.cds.StorageSrv;
import com.rbkmoney.woody.api.ClientBuilder;
import com.rbkmoney.woody.api.event.ClientEventListener;
import com.rbkmoney.woody.api.event.CompositeClientEventListener;
import com.rbkmoney.woody.thrift.impl.http.THSpawnClientBuilder;
import com.rbkmoney.woody.thrift.impl.http.event.ClientEventLogListener;
import com.rbkmoney.woody.thrift.impl.http.event.HttpClientEventLogListener;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.Resource;
@ -22,24 +16,10 @@ public class CdsStorageConfiguration {
private Resource resource;
@Bean
public StorageSrv.Iface storageSrv(ClientEventListener listenerSrv) throws IOException {
return clientBuilder()
.withEventListener(listenerSrv)
public StorageSrv.Iface storageSrv() throws IOException {
return new THSpawnClientBuilder()
.withAddress(resource.getURI())
.build(StorageSrv.Iface.class);
}
@Bean
@ConditionalOnMissingBean
public ClientEventListener listenerSrv() {
return new CompositeClientEventListener(
new ClientEventLogListener(),
new HttpClientEventLogListener()
);
}
@Bean(name = "clientBuilderStorage")
public ClientBuilder clientBuilder() {
return new THSpawnClientBuilder();
}
}

View File

@ -1,14 +1,8 @@
package com.rbkmoney.proxy.mocketbank.configuration;
import com.rbkmoney.damsel.proxy_provider.ProviderProxyHostSrv;
import com.rbkmoney.woody.api.ClientBuilder;
import com.rbkmoney.woody.api.event.ClientEventListener;
import com.rbkmoney.woody.api.event.CompositeClientEventListener;
import com.rbkmoney.woody.thrift.impl.http.THSpawnClientBuilder;
import com.rbkmoney.woody.thrift.impl.http.event.ClientEventLogListener;
import com.rbkmoney.woody.thrift.impl.http.event.HttpClientEventLogListener;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.Resource;
@ -22,25 +16,10 @@ public class HellGateConfiguration {
private Resource resource;
@Bean
public ProviderProxyHostSrv.Iface providerProxyHost(ClientEventListener listenerSrv) throws IOException {
return clientBuilder()
.withEventListener(listenerSrv)
public ProviderProxyHostSrv.Iface providerProxyHost() throws IOException {
return new THSpawnClientBuilder()
.withAddress(resource.getURI())
.build(ProviderProxyHostSrv.Iface.class);
}
@Bean
@ConditionalOnMissingBean
public ClientEventListener listenerSrv() {
return new CompositeClientEventListener(
new ClientEventLogListener(),
new HttpClientEventLogListener()
);
}
@Bean(name = "clientBuilderHellgate")
public ClientBuilder clientBuilder() {
return new THSpawnClientBuilder();
}
}

View File

@ -226,7 +226,11 @@ public class MocketBankServerHandler implements ProviderProxySrv.Iface {
}
private ProxyResult cancelled(Context context) {
ProxyResult proxyResult = ProxyProviderWrapper.makeProxyResultFailure("Unsupported method CANCEL", "Unsupported method CANCEL");
ProxyResult proxyResult = ProxyProviderWrapper.makeProxyResult(
ProxyWrapper.makeFinishIntentSuccess(),
"cancelled".getBytes(),
context.getPaymentInfo().getPayment().getTrx()
);
LOGGER.error("Cancelled: proxyResult {}", proxyResult);
return proxyResult;
}

View File

@ -1,51 +1,22 @@
package com.rbkmoney.proxy.mocketbank.utils.cds;
import com.rbkmoney.damsel.cds.*;
import com.rbkmoney.damsel.cds.CardData;
import com.rbkmoney.damsel.cds.PutCardDataResult;
import com.rbkmoney.damsel.cds.StorageSrv;
import org.apache.thrift.TException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.nio.ByteBuffer;
import java.util.List;
@Component
public class CdsApi {
private final static Logger LOGGER = LoggerFactory.getLogger(CdsApi.class);
@Autowired
private KeyringSrv.Iface keyringSrv;
@Autowired
private StorageSrv.Iface storageSrv;
/**
* Разблокировать ключи
*
* @param key_share ByteBuffer
* @return UnlockStatus
* @throws TException
*/
public UnlockStatus unlock(ByteBuffer key_share) throws TException {
LOGGER.info("Keyring: unlock");
return keyringSrv.unlock(key_share);
}
/**
* Инициализация ключей
*
* @param threshold short
* @param num_shares short
* @return List<ByteBuffer>
* @throws TException
*/
public List<ByteBuffer> init(short threshold, short num_shares) throws TException {
LOGGER.info("Keyring: init");
return keyringSrv.init(threshold, num_shares);
}
/**
* Получить карточные данные без CVV
*

View File

@ -2,7 +2,6 @@ package com.rbkmoney.proxy.mocketbank.handler;
import com.rbkmoney.damsel.cds.CardData;
import com.rbkmoney.damsel.cds.PutCardDataResult;
import com.rbkmoney.damsel.cds.UnlockStatus;
import com.rbkmoney.damsel.domain.TargetInvoicePaymentStatus;
import com.rbkmoney.damsel.domain.TransactionInfo;
import com.rbkmoney.damsel.proxy_provider.Context;
@ -27,10 +26,8 @@ import org.springframework.test.context.junit4.SpringRunner;
import java.io.IOException;
import java.net.URISyntaxException;
import java.nio.ByteBuffer;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static org.junit.Assert.assertTrue;
@ -197,26 +194,4 @@ public class MocketBankServerHandlerFailIntegrationTest {
return putCardDataResponse;
}
/**
* CDS unlock Key
* <p>
* TODO: Игнорируем, если ключи уже разблокированы
*
* @param thres_hold short
* @param num_shares short
* @return UnlockStatus
* @throws URISyntaxException
* @throws TException
*/
private UnlockStatus cdsUnlockKey(short thres_hold, short num_shares) throws URISyntaxException, TException, IOException {
LOGGER.info("CDS: init");
List<ByteBuffer> key = cds.init(thres_hold, num_shares);
LOGGER.info("CDS: init response {}", key.toString());
LOGGER.info("CDS: unlock");
UnlockStatus unlockStatus = cds.unlock(key.get(0));
LOGGER.info("CDS: unlock res {}", unlockStatus.toString());
return unlockStatus;
}
}

View File

@ -2,7 +2,6 @@ package com.rbkmoney.proxy.mocketbank.handler;
import com.rbkmoney.damsel.cds.CardData;
import com.rbkmoney.damsel.cds.PutCardDataResult;
import com.rbkmoney.damsel.cds.UnlockStatus;
import com.rbkmoney.damsel.domain.TargetInvoicePaymentStatus;
import com.rbkmoney.damsel.domain.TransactionInfo;
import com.rbkmoney.damsel.proxy_provider.CallbackResult;
@ -31,7 +30,6 @@ import java.net.URISyntaxException;
import java.nio.ByteBuffer;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static org.junit.Assert.assertTrue;
@ -200,26 +198,4 @@ public class MocketBankServerHandlerFailWith3DSIntegrationTest {
return putCardDataResponse;
}
/**
* CDS unlock Key
* <p>
* TODO: Игнорируем, если ключи уже разблокированы
*
* @param thres_hold short
* @param num_shares short
* @return UnlockStatus
* @throws URISyntaxException
* @throws TException
*/
private UnlockStatus cdsUnlockKey(short thres_hold, short num_shares) throws URISyntaxException, TException, IOException {
LOGGER.info("CDS: init");
List<ByteBuffer> key = cds.init(thres_hold, num_shares);
LOGGER.info("CDS: init response {}", key.toString());
LOGGER.info("CDS: unlock");
UnlockStatus unlockStatus = cds.unlock(key.get(0));
LOGGER.info("CDS: unlock res {}", unlockStatus.toString());
return unlockStatus;
}
}

View File

@ -2,7 +2,6 @@ package com.rbkmoney.proxy.mocketbank.handler;
import com.rbkmoney.damsel.cds.CardData;
import com.rbkmoney.damsel.cds.PutCardDataResult;
import com.rbkmoney.damsel.cds.UnlockStatus;
import com.rbkmoney.damsel.domain.TargetInvoicePaymentStatus;
import com.rbkmoney.damsel.domain.TransactionInfo;
import com.rbkmoney.damsel.proxy_provider.Context;
@ -28,10 +27,8 @@ import org.springframework.test.context.junit4.SpringRunner;
import java.io.IOException;
import java.net.URISyntaxException;
import java.nio.ByteBuffer;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static org.junit.Assert.assertEquals;
@ -215,26 +212,4 @@ public class MocketBankServerHandlerSuccessIntegrationTest {
return putCardDataResponse;
}
/**
* CDS unlock Key
* <p>
* TODO: Игнорируем, если ключи уже разблокированы
*
* @param thres_hold short
* @param num_shares short
* @return UnlockStatus
* @throws URISyntaxException
* @throws TException
*/
private UnlockStatus cdsUnlockKey(short thres_hold, short num_shares) throws URISyntaxException, TException, IOException {
LOGGER.info("CDS: init");
List<ByteBuffer> key = cds.init(thres_hold, num_shares);
LOGGER.info("CDS: init response {}", key.toString());
LOGGER.info("CDS: unlock");
UnlockStatus unlockStatus = cds.unlock(key.get(0));
LOGGER.info("CDS: unlock res {}", unlockStatus.toString());
return unlockStatus;
}
}

View File

@ -2,7 +2,6 @@ package com.rbkmoney.proxy.mocketbank.handler;
import com.rbkmoney.damsel.cds.CardData;
import com.rbkmoney.damsel.cds.PutCardDataResult;
import com.rbkmoney.damsel.cds.UnlockStatus;
import com.rbkmoney.damsel.domain.TargetInvoicePaymentStatus;
import com.rbkmoney.damsel.domain.TransactionInfo;
import com.rbkmoney.damsel.proxy_provider.*;
@ -29,7 +28,6 @@ import java.net.URISyntaxException;
import java.nio.ByteBuffer;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static org.junit.Assert.assertEquals;
@ -214,26 +212,4 @@ public class MocketBankServerHandlerSuccessWith3DSIntegrationTest {
return putCardDataResponse;
}
/**
* CDS unlock Key
* <p>
* TODO: Игнорируем, если ключи уже разблокированы
*
* @param thres_hold short
* @param num_shares short
* @return UnlockStatus
* @throws URISyntaxException
* @throws TException
*/
private UnlockStatus cdsUnlockKey(short thres_hold, short num_shares) throws URISyntaxException, TException, IOException {
LOGGER.info("CDS: init");
List<ByteBuffer> key = cds.init(thres_hold, num_shares);
LOGGER.info("CDS: init response {}", key.toString());
LOGGER.info("CDS: unlock");
UnlockStatus unlockStatus = cds.unlock(key.get(0));
LOGGER.info("CDS: unlock res {}", unlockStatus.toString());
return unlockStatus;
}
}

View File

@ -1,64 +0,0 @@
package com.rbkmoney.proxy.mocketbank.utils.cds;
import com.rbkmoney.damsel.cds.CardData;
import com.rbkmoney.damsel.cds.PutCardDataResult;
import com.rbkmoney.damsel.cds.UnlockStatus;
import com.rbkmoney.damsel.cds.Unlocked;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import java.nio.ByteBuffer;
import java.util.LinkedList;
import java.util.List;
import static org.junit.Assert.assertEquals;
public class CdsApiTest {
@Mock
private CdsApi cds;
@Mock
private Unlocked unlocked;
@Mock
private CardData cardData;
@Mock
private PutCardDataResult putCardDataResult;
@Before
public void setUp() throws Exception {
// this must be called for the @Mock annotations above to be processed
// and for the mock service to be injected into the controller under test.
MockitoAnnotations.initMocks(this);
}
@Test
public void testUnlock() throws Exception {
ByteBuffer bbuf = ByteBuffer.allocate(10);
UnlockStatus status = UnlockStatus.unlocked(unlocked);
Mockito.when(cds.unlock(bbuf)).thenReturn(status);
assertEquals(status, cds.unlock(bbuf));
}
@Test
public void testInit() throws Exception {
short threshold = 1;
short num_shares = 1;
List<ByteBuffer> list = new LinkedList<>();
ByteBuffer bbuf = ByteBuffer.allocate(10);
list.add(bbuf);
Mockito.when(cds.init(threshold, num_shares)).thenReturn(list);
assertEquals(list, cds.init(threshold, num_shares));
}
}