当前位置: 首页>>代码示例>>Java>>正文


Java BsonInvalidOperationException类代码示例

本文整理汇总了Java中org.bson.BsonInvalidOperationException的典型用法代码示例。如果您正苦于以下问题:Java BsonInvalidOperationException类的具体用法?Java BsonInvalidOperationException怎么用?Java BsonInvalidOperationException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


BsonInvalidOperationException类属于org.bson包,在下文中一共展示了BsonInvalidOperationException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: method_decode_should_evocate_functions_that_reade_user_attributes

import org.bson.BsonInvalidOperationException; //导入依赖的package包/类
@Test
public void method_decode_should_evocate_functions_that_reade_user_attributes() throws Exception {
    DecoderContext decoderContext = DecoderContext.builder().build();
    PowerMockito.when(reader.readString("password")).thenReturn(PASSWORD);
    PowerMockito.when(reader.readString("phone")).thenReturn(PHONE);
    PowerMockito.when(reader.readBoolean("enable")).thenReturn(ENABLE);
    PowerMockito.when(reader.readBoolean("extraction")).thenReturn(EXTRACTIONENABLED);
    PowerMockito.when(reader.readString("surname")).thenReturn(SURNAME);
    PowerMockito.when(reader.readString("name")).thenReturn(NAME);
    PowerMockito.when(reader.readBoolean("adm")).thenReturn(ADMIN);
    PowerMockito.when(reader.readString("uuid")).thenReturn(UUIDString);
    PowerMockito.when(reader.readString("email")).thenReturn(EMAIL);
    PowerMockito.when(reader.readString("acronym")).thenReturn(FIELDCENTERACRONYM);
    PowerMockito.when(reader.readBsonType()).thenReturn(BsonType.END_OF_DOCUMENT);
    doThrow(new BsonInvalidOperationException("teste")).when(reader).readNull("fieldCenter");
    doThrow(new BsonInvalidOperationException("teste")).when(reader).readNull("extraction");
    User userLocal = UserCodec.decode(reader,  decoderContext);
    assertEquals(userLocal.getEmail(),EMAIL);
    assertEquals(userLocal.getPassword(),PASSWORD);
    assertEquals(userLocal.getPhone(),PHONE);
    assertEquals(userLocal.isEnable(),ENABLE);
    assertEquals(userLocal.isExtractionEnabled(),EXTRACTIONENABLED);
    assertEquals(userLocal.getName(),NAME);
    assertEquals(userLocal.getFieldCenter().getAcronym(),FIELDCENTERACRONYM);
    assertEquals(userLocal.getUuid().toString(),UUID.fromString(UUIDString).toString());
}
 
开发者ID:ccem-dev,项目名称:otus-api,代码行数:27,代码来源:UserCodecTest.java

示例2: decode

import org.bson.BsonInvalidOperationException; //导入依赖的package包/类
@Override
public T decode(BsonReader reader, DecoderContext decoderContext) {
	final BsonType type = reader.getCurrentBsonType();
	switch(type) {
	case INT32:
		return decode(reader.readInt32() != 0);
	case NULL:
		return null;
	case STRING:
		return decode(Boolean.parseBoolean(reader.readString()));
	case BOOLEAN:
		return decode(reader.readBoolean());
		//$CASES-OMITTED$
	default:
		final String errMsg = format("Invalid date type, found: %s", type);
		throw new BsonInvalidOperationException(errMsg); 
	}
}
 
开发者ID:JPDSousa,项目名称:mongo-obj-framework,代码行数:19,代码来源:AbstractBooleanCodec.java

示例3: decode

import org.bson.BsonInvalidOperationException; //导入依赖的package包/类
@Override
public T decode(BsonReader reader, DecoderContext decoderContext) {
	final BsonType type = reader.getCurrentBsonType();
	switch(type) {
	case DATE_TIME:
		return decode(reader.readDateTime());
	case DOUBLE:
		return decode((long) reader.readDouble());
	case INT32:
		return decode(reader.readInt32());
	case INT64:
		return decode(reader.readInt64());
	case NULL:
		return null;
	case STRING:
		return decode(Long.valueOf(reader.readString()));
		//$CASES-OMITTED$
	default:
		final String errMsg = format("Invalid date type, found: %s", type);
		throw new BsonInvalidOperationException(errMsg); 
	}
}
 
开发者ID:JPDSousa,项目名称:mongo-obj-framework,代码行数:23,代码来源:AbstractTimeCodec.java

示例4: parse

import org.bson.BsonInvalidOperationException; //导入依赖的package包/类
/**
 * @param json
 * @return either a BsonDocument or a BsonArray from the json string
 * @throws JsonParseException
 */
public static BsonValue parse(String json)
        throws JsonParseException {
    if (json == null) {
        return null;
    }

    String trimmed = json.trim();

    if (trimmed.startsWith("{")) {
        try {
            return BsonDocument.parse(json);
        } catch (BsonInvalidOperationException ex) {
            // this can happen parsing a bson type, e.g.
            // {"$oid": "xxxxxxxx" }
            // the string starts with { but is not a document
            return getBsonValue(json);
        }
    } else if (trimmed.startsWith("[")) {
        return BSON_ARRAY_CODEC.decode(
                new JsonReader(json),
                DecoderContext.builder().build());
    } else {
        return getBsonValue(json);
    }
}
 
开发者ID:SoftInstigate,项目名称:restheart,代码行数:31,代码来源:JsonUtils.java

示例5: write_map_with_null_values_to_bson

import org.bson.BsonInvalidOperationException; //导入依赖的package包/类
@Test public void
write_map_with_null_values_to_bson() {
    Map<String, Integer> mapToSerialise = new HashMap<>();
    mapToSerialise.put("foo", 42);
    mapToSerialise.put("bar", null);

    BsonDocument doc = (BsonDocument) BsonMapSerialiser
            .writingValuesWith(BsonSerialisers.toInteger)
            .apply(mapToSerialise);

    assertEquals("invalid foo", 42, doc.getInt32("foo").getValue());
    try {
        Integer value = doc.getInt32("bar").getValue();
        fail("bar should not have been written to the document");
    } catch (BsonInvalidOperationException e) {
        // expected
    }
}
 
开发者ID:poetix,项目名称:octarine,代码行数:19,代码来源:SerialisationTest.java

示例6: fromBson

import org.bson.BsonInvalidOperationException; //导入依赖的package包/类
@Override
public <T> T fromBson(BsonValue value, Class<T> type, SmofField fieldOpts) {
	checkArgument(value != null, "A value must be specified.");
	checkArgument(type != null, "A type must be specified.");
	final Codec<T> codec = getCodec(type);
	try {
		return deserializeWithCodec(codec, value);
	} catch (BsonInvalidOperationException e) {
		handleError(new RuntimeException("Cannot parse value for type: " + fieldOpts.getName(), e));
		return null;
	}
}
 
开发者ID:JPDSousa,项目名称:mongo-obj-framework,代码行数:13,代码来源:AbstractBsonParser.java

示例7: decode

import org.bson.BsonInvalidOperationException; //导入依赖的package包/类
@Override
public T decode(BsonReader reader, DecoderContext decoderContext) {
	try {
		return Enum.valueOf(clazz, reader.readString());
	} catch (IllegalArgumentException e) {
		throw new BsonInvalidOperationException(e.getMessage());
	}
}
 
开发者ID:JPDSousa,项目名称:mongo-obj-framework,代码行数:9,代码来源:EnumCodec.java

示例8: decode

import org.bson.BsonInvalidOperationException; //导入依赖的package包/类
@Override
public T decode(BsonReader reader, DecoderContext decoderContext) {
	final BsonType type = reader.getCurrentBsonType();
	switch(type) {
	case DATE_TIME:
		return decode(Long.toString(reader.readDateTime()));
	case DOUBLE:
		return decode(Double.toString(reader.readDouble()));
	case INT32:
		return decode(Integer.toString(reader.readInt32()));
	case INT64:
		return decode(Long.toString(reader.readInt64()));
	case NULL:
		return null;
	case STRING:
		return decode(reader.readString());
	case BINARY:
		return decode(new String(reader.readBinaryData().getData()));
	case BOOLEAN:
		return decode(Boolean.toString(reader.readBoolean()));
	case JAVASCRIPT:
		return decode(reader.readJavaScript());
	case JAVASCRIPT_WITH_SCOPE:
		return decode(reader.readJavaScriptWithScope());
	case OBJECT_ID:
		return decode(reader.readObjectId().toHexString());
	case REGULAR_EXPRESSION:
		return decode(reader.readRegularExpression().getPattern());
	case SYMBOL:
		return decode(reader.readSymbol());
		//$CASES-OMITTED$
	default:
		final String errMsg = format("Invalid date type, found: %s", type);
		throw new BsonInvalidOperationException(errMsg); 
	}
}
 
开发者ID:JPDSousa,项目名称:mongo-obj-framework,代码行数:37,代码来源:AbstractStringCodec.java

示例9: decode

import org.bson.BsonInvalidOperationException; //导入依赖的package包/类
@Override
public T decode(BsonReader reader, DecoderContext decoderContext) {
	final BsonType type = reader.getCurrentBsonType();
	if(type == BsonType.BINARY) {
		return decode(reader.readBinaryData());
	}
	final String errMsg = format("Invalid date type, found: %s", type);
	throw new BsonInvalidOperationException(errMsg); 
}
 
开发者ID:JPDSousa,项目名称:mongo-obj-framework,代码行数:10,代码来源:AbstractBytesCodec.java

示例10: getInstance

import org.bson.BsonInvalidOperationException; //导入依赖的package包/类
private Collection<Byte> getInstance() {
	try {
		return CollectionUtils.create(encoderClass);
	} catch (InstantiationException | IllegalAccessException | IllegalArgumentException 
			| SecurityException e) {
		throw new BsonInvalidOperationException(e.getMessage());
	}
}
 
开发者ID:JPDSousa,项目名称:mongo-obj-framework,代码行数:9,代码来源:ByteCollectionCodec.java

示例11: decode

import org.bson.BsonInvalidOperationException; //导入依赖的package包/类
@Override
public Float decode(final BsonReader reader, final DecoderContext decoderContext) {
    double value = reader.readDouble();
    if (value < -Float.MAX_VALUE || value > Float.MAX_VALUE) {
        throw new BsonInvalidOperationException(format("%s can not be converted into a Float.", value));
    }
    return (float) value;
}
 
开发者ID:andyphillips404,项目名称:awplab-core,代码行数:9,代码来源:CorrectedFloatCodec.java

示例12: decode

import org.bson.BsonInvalidOperationException; //导入依赖的package包/类
@Override
public Class decode(BsonReader reader, DecoderContext decoderContext) {
	String className = reader.readString();
	try {
		return Class.forName(className);
	}
	catch (ClassNotFoundException e) {
		throw new BsonInvalidOperationException(
				String.format("Cannot create class from string '%s'", className));
	}
}
 
开发者ID:ralscha,项目名称:bsoncodec,代码行数:12,代码来源:ClassStringCodec.java

示例13: decode

import org.bson.BsonInvalidOperationException; //导入依赖的package包/类
@Override
public URL decode(BsonReader reader, DecoderContext decoderContext) {
	String urlString = reader.readString();
	try {
		return new URL(urlString);
	}
	catch (MalformedURLException e) {
		throw new BsonInvalidOperationException(
				String.format("Cannot create URL from string '%s'", urlString));

	}
}
 
开发者ID:ralscha,项目名称:bsoncodec,代码行数:13,代码来源:URLStringCodec.java

示例14: decode

import org.bson.BsonInvalidOperationException; //导入依赖的package包/类
@Override
public URI decode(BsonReader reader, DecoderContext decoderContext) {
	String uriString = reader.readString();
	try {
		return new URI(uriString);
	}
	catch (URISyntaxException e) {
		throw new BsonInvalidOperationException(
				String.format("Cannot create URI from string '%s'", uriString));

	}
}
 
开发者ID:ralscha,项目名称:bsoncodec,代码行数:13,代码来源:URIStringCodec.java

示例15: addDecodeStatements

import org.bson.BsonInvalidOperationException; //导入依赖的package包/类
@Override
public void addDecodeStatements(TypeMirror type, CodeGeneratorContext ctx) {
	Builder builder = ctx.builder();
	switch (type.getKind()) {
	case BOOLEAN:
		builder.addStatement(ctx.setter("reader.readBoolean()"));
		break;
	case BYTE:
		builder.addStatement(ctx.setter("(byte)reader.readInt32()"));
		break;
	case SHORT:
		builder.addStatement(ctx.setter("(short)reader.readInt32()"));
		break;
	case INT:
		builder.addStatement(ctx.setter("reader.readInt32()"));
		break;
	case LONG:
		builder.addStatement(ctx.setter("reader.readInt64()"));
		break;
	case CHAR:
		builder.addStatement("String string = reader.readString()");
		builder.beginControlFlow("if (string.length() != 1)");
		builder.addStatement(
				"throw new $T(String.format(\"Attempting to builder the string '%s' to a character, but its length is not equal to one\", string))",
				BsonInvalidOperationException.class);
		builder.endControlFlow();
		builder.addStatement(ctx.setter("string.charAt(0)"));
		break;
	case FLOAT:
		builder.addStatement(ctx.setter("(float)reader.readDouble()"));
		break;
	case DOUBLE:
		builder.addStatement(ctx.setter("reader.readDouble()"));
		break;
	default:
		break;
	}

}
 
开发者ID:ralscha,项目名称:bsoncodec-apt,代码行数:40,代码来源:PrimitiveDelegate.java


注:本文中的org.bson.BsonInvalidOperationException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。